Type Alias rocket::request::FlashMessage

source ·
pub type FlashMessage<'a> = Flash<&'a CookieJar<'a>>;
Expand description

Type alias to retrieve Flash messages from a request.

A FlashMessage holds the parsed contents of the flash cookie. As long as there is a flash cookie present (set by the Flash Responder), a FlashMessage request guard will succeed.

The flash cookie is cleared if either the kind() or message() method is called. If neither method is called, the flash cookie is not cleared.

Aliased Type§

struct FlashMessage<'a> { /* private fields */ }

Implementations§

source§

impl<'r> FlashMessage<'r>

source

pub fn into_inner(self) -> (String, String)

Returns a tuple of (kind, message), consuming self.

source

pub fn kind(&self) -> &str

Returns the kind of this message.

source

pub fn message(&self) -> &str

Returns the message contents of this message.

source§

impl<R> Flash<R>

source

pub fn new<K: Into<String>, M: Into<String>>( res: R, kind: K, message: M ) -> Flash<R>

Constructs a new Flash message with the given kind, message, and underlying responder.

Examples

Construct a “suggestion” message with contents “Try this out!” that redirects to “/”.

use rocket::response::{Redirect, Flash};

let message = Flash::new(Redirect::to("/"), "suggestion", "Try this out!");
source

pub fn success<S: Into<String>>(responder: R, message: S) -> Flash<R>

Constructs a “success” Flash message with the given responder and message.

Examples

Construct a “success” message with contents “It worked!” that redirects to “/”.

use rocket::response::{Redirect, Flash};

let message = Flash::success(Redirect::to("/"), "It worked!");
source

pub fn warning<S: Into<String>>(responder: R, message: S) -> Flash<R>

Constructs a “warning” Flash message with the given responder and message.

Examples

Construct a “warning” message with contents “Watch out!” that redirects to “/”.

use rocket::response::{Redirect, Flash};

let message = Flash::warning(Redirect::to("/"), "Watch out!");
source

pub fn error<S: Into<String>>(responder: R, message: S) -> Flash<R>

Constructs an “error” Flash message with the given responder and message.

Examples

Construct an “error” message with contents “Whoops!” that redirects to “/”.

use rocket::response::{Redirect, Flash};

let message = Flash::error(Redirect::to("/"), "Whoops!");

Trait Implementations§

source§

impl<R: Debug> Debug for Flash<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'r> FromRequest<'r> for FlashMessage<'r>

Retrieves a flash message from a flash cookie. If there is no flash cookie, or if the flash cookie is malformed, an empty Err is returned.

The suggested use is through an Option and the FlashMessage type alias in request: Option<FlashMessage>.

§

type Error = ()

The associated error to be returned if derivation fails.
source§

fn from_request<'life0, 'async_trait>( req: &'r Request<'life0> ) -> Pin<Box<dyn Future<Output = Outcome<Self, Self::Error>> + Send + 'async_trait>>where Self: 'async_trait, 'r: 'async_trait, 'life0: 'async_trait,

Derives an instance of Self from the incoming request metadata. Read more
source§

impl<'r, 'o: 'r, R: Responder<'r, 'o>> Responder<'r, 'o> for Flash<R>

Sets the message cookie and then uses the wrapped responder to complete the response. In other words, simply sets a cookie and delegates the rest of the response handling to the wrapped responder. As a result, the Outcome of the response is the Outcome of the wrapped Responder.

source§

fn respond_to(self, req: &'r Request<'_>) -> Result<'o>

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more
source§

impl Serialize for FlashMessage<'_>

source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more