Skip to main content

Flash

Struct Flash 

Source
pub struct Flash(/* private fields */);
Expand description

Flash messages set by the previous request, as an extractor.

Extracting them removes them from the session, so each message shows once (Rails’ flash). Rejects like Session when used outside serve or when the secret is missing.

In templates: {% if let Some(notice) = flash.notice() %}<p>{{ notice }}</p>{% endif %}.

§Examples

use ocre::Flash;

async fn index(flash: Flash) -> String {
    flash.iter().map(|(kind, message)| format!("{kind}: {message}\n")).collect()
}

Implementations§

Source§

impl Flash

Source

pub fn get(&self, kind: &str) -> Option<&str>

The message of the given kind, if the previous request set one.

§Examples
assert_eq!(ocre::Flash::default().get("warning"), None);
Source

pub fn notice(&self) -> Option<&str>

The notice message (success), same as flash.get("notice").

§Examples
assert_eq!(ocre::Flash::default().notice(), None);
Source

pub fn alert(&self) -> Option<&str>

The alert message (failure), same as flash.get("alert").

§Examples
assert_eq!(ocre::Flash::default().alert(), None);
Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>

Every (kind, message) pair.

§Examples
assert_eq!(ocre::Flash::default().iter().count(), 0);
Source

pub fn is_empty(&self) -> bool

Whether there is no message.

§Examples
assert!(ocre::Flash::default().is_empty());
Source

pub fn now(self, kind: &str, message: impl Into<String>) -> Self

These messages plus message of kind, for this response only (Rails’ flash.now): render a page with a message without storing it in the session, e.g. a form shown again with an alert.

§Examples
let flash = ocre::Flash::default().now("alert", "Check the highlighted fields.");
assert_eq!(flash.alert(), Some("Check the highlighted fields."));
assert_eq!(flash.clone().now("alert", "Again.").alert(), Some("Again."), "a kind has one message");

Trait Implementations§

Source§

impl Clone for Flash

Source§

fn clone(&self) -> Flash

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Flash

Source§

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

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

impl Default for Flash

Source§

fn default() -> Flash

Returns the “default value” for a type. Read more
Source§

impl Eq for Flash

Source§

impl<S: Sync> FromRequestParts<S> for Flash

Source§

type Rejection = Error

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Error>

Perform the extraction.
Source§

impl PartialEq for Flash

Source§

fn eq(&self, other: &Flash) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Flash

Auto Trait Implementations§

§

impl Freeze for Flash

§

impl RefUnwindSafe for Flash

§

impl Send for Flash

§

impl Sync for Flash

§

impl Unpin for Flash

§

impl UnsafeUnpin for Flash

§

impl UnwindSafe for Flash

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V