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.
Flash Cookie
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>
impl<'r> FlashMessage<'r>
source§impl<R> Flash<R>
impl<R> Flash<R>
sourcepub fn new<K: Into<String>, M: Into<String>>(
res: R,
kind: K,
message: M
) -> Flash<R>
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!");sourcepub fn success<S: Into<String>>(responder: R, message: S) -> Flash<R>
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!");sourcepub fn warning<S: Into<String>>(responder: R, message: S) -> Flash<R>
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!");sourcepub fn error<S: Into<String>>(responder: R, message: S) -> Flash<R>
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> FromRequest<'r> for FlashMessage<'r>
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>.
source§impl<'r, 'o: 'r, R: Responder<'r, 'o>> Responder<'r, 'o> for Flash<R>
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.