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
impl Flash
Sourcepub fn get(&self, kind: &str) -> Option<&str>
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);Sourcepub fn notice(&self) -> Option<&str>
pub fn notice(&self) -> Option<&str>
The notice message (success), same as flash.get("notice").
§Examples
assert_eq!(ocre::Flash::default().notice(), None);Sourcepub fn alert(&self) -> Option<&str>
pub fn alert(&self) -> Option<&str>
The alert message (failure), same as flash.get("alert").
§Examples
assert_eq!(ocre::Flash::default().alert(), None);Sourcepub fn now(self, kind: &str, message: impl Into<String>) -> Self
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§
impl Eq for Flash
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
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
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
§type Rejection = <T as FromRequestParts<S>>::Rejection
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>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.