Skip to main content

Toast

Struct Toast 

Source
#[non_exhaustive]
pub struct Toast { pub title: String, pub body: String, pub tone: ToastVariant, /* private fields */ }
Expand description

One notice in a Toaster: a title, an optional description, and an id.

The id tells toasts apart while the list changes, and nothing outside this type sets it. On the server, Toast::new numbers each toast from a counter of the process, so toasts made in one process have different ids until 2³² of them have been made. In the browser, Toast::push and Toast::push_expr give a toast one more than the highest id in the list. A clone keeps its id, so a list that holds a toast and its clone repeats one; the runtime then tells the two apart by position and writes a warning to the console.

use hypersig::{Expr, Signals};
use hypersig_ui::{Toast, ToastVariant};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct App {
    toasts: Vec<Toast>,
    name: String,
}

// On the server, in the list a patch sends.
let failed = App::toasts().patch(vec![
    Toast::new("Upload failed").variant(ToastVariant::Destructive),
]);

// In the browser, with fixed text.
let saved = Toast::new("Saved").description("Your changes are live.").push(App::toasts());

// In the browser, with text from a signal.
let renamed = Toast::push_expr(
    App::toasts(),
    Expr::lit(&Toast::new("Renamed")).with(Toast::body(), App::name().concat(" is the new name.")),
);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§title: String

The title, in bold.

§body: String

The line under the title, hidden while it is empty.

§tone: ToastVariant

How the toast is drawn.

Implementations§

Source§

impl Toast

Source

pub fn title() -> Sig<Self, String>

Typed reference to the title signal.

Source

pub fn body() -> Sig<Self, String>

Typed reference to the body signal.

Source

pub fn tone() -> Sig<Self, ToastVariant>

Typed reference to the tone signal.

Source§

impl Toast

Source

pub fn new(title: impl Into<String>) -> Self

A toast titled title, with an id no other toast of the process has.

Source

pub fn description(self, text: impl Into<String>) -> Self

Adds a line of text under the title.

Source

pub fn variant(self, variant: ToastVariant) -> Self

Sets the look of the toast.

Source

pub fn push<S>(self, toasts: Sig<S, Vec<Self>>) -> Stmt<S>

A statement that adds this toast to toasts in the browser.

Source

pub fn push_expr<S>( toasts: Sig<S, Vec<Self>>, toast: impl IntoExpr<S, Self>, ) -> Stmt<S>

A statement that adds toast, which the browser evaluates, to toasts.

Build toast from a literal toast with Expr::with on Toast::title, Toast::body, or Toast::tone, so that its text can come from a signal. Its id is replaced by one more than the highest id in toasts.

Trait Implementations§

Source§

impl Clone for Toast

Source§

fn clone(&self) -> Toast

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 Toast

Source§

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

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

impl<'de> Deserialize<'de> for Toast

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Toast

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Toast

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Signals for Toast

Source§

impl StructuralPartialEq for Toast

Auto Trait Implementations§

§

impl Freeze for Toast

§

impl RefUnwindSafe for Toast

§

impl Send for Toast

§

impl Sync for Toast

§

impl Unpin for Toast

§

impl UnsafeUnpin for Toast

§

impl UnwindSafe for Toast

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
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.
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.

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.