rocket::request

Type Alias FlashMessage

Source
pub type FlashMessage<'a, 'r> = Flash<&'a Request<'r>>;
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 name() or msg() method is called. If neither method is called, the flash cookie is not cleared.

Aliased Type§

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

Implementations

Source§

impl<'a, 'r> Flash<&'a Request<'r>>

Source

pub fn name(&self) -> &str

Returns the name of this message.

Source

pub fn msg(&self) -> &str

Returns the msg contents of this message.

Source§

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

Source

pub fn new<N: AsRef<str>, M: AsRef<str>>(res: R, name: N, msg: M) -> Flash<R>

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

§Examples

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

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

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

pub fn success<S: AsRef<str>>(responder: R, msg: S) -> Flash<R>

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

§Examples

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

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

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

pub fn warning<S: AsRef<str>>(responder: R, msg: S) -> Flash<R>

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

§Examples

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

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

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

pub fn error<S: AsRef<str>>(responder: R, msg: S) -> Flash<R>

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

§Examples

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

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

let msg = 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<'a, 'r> FromRequest<'a, 'r> for Flash<&'a Request<'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§

type Error = ()

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

fn from_request(req: &'a Request<'r>) -> Outcome<Self, Self::Error>

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

impl<'r, R: Responder<'r>> Responder<'r> 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: &Request<'_>) -> Result<Response<'r>, Status>

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