Skip to main content

Toast

Struct Toast 

Source
pub struct Toast { /* private fields */ }
Expand description

Toast — a present-able request (NOT a Widget). Construct with one of the severity-named constructors, configure via builder methods, then call .present(ctx) or ctx.show_toast(self). Internally the builder is consumed and its data is moved into a slot on the installed ToastHost.

See the module docs for the full conceptual overview.

Implementations§

Source§

impl Toast

Source

pub fn info(title: impl Into<LocalizedString>) -> Self

Info-severity toast (status confirmation, neutral notice).

Source

pub fn success(title: impl Into<LocalizedString>) -> Self

Success-severity toast (“Saved”, “Connected”, “Build finished”).

Source

pub fn warning(title: impl Into<LocalizedString>) -> Self

Warning-severity toast.

Source

pub fn error(title: impl Into<LocalizedString>) -> Self

Error-severity toast. Defaults to Live::Assertive.

Source

pub fn loading(title: impl Into<LocalizedString>) -> Self

Loading-style toast — Info severity with a Spinner as the leading widget. Persistent by default; the app calls ToastHandle::dismiss (typically from the operation’s completion callback) or replaces it with a success/error toast.

Source

pub fn body(self, text: impl Into<LocalizedString>) -> Self

Optional secondary line below the title.

Source

pub fn leading(self, widget: impl Widget + 'static) -> Self

Replace the default severity glyph with a custom leading widget (spinner, app icon, avatar). Boxes the widget so the toast remains object-safe.

Source

pub fn action(self, action: ToastAction) -> Self

Append a ToastAction (link or button) to the toast.

Source

pub fn primary_action( self, label: impl Into<LocalizedString>, on_invoke: impl Fn(&mut EventContext<'_>) + 'static, ) -> Self

Shorthand for appending a filled-button primary action — equivalent to .action(ToastAction::primary(label, on_invoke)).

Source

pub fn auto_dismiss_after(self, duration: Duration) -> Self

Override the auto-dismiss countdown. Pass Duration::ZERO for immediate dismissal on the next timer tick; call persistent to disable the timer entirely.

Source

pub fn persistent(self) -> Self

Disable auto-dismiss — the toast persists until the user clicks the close X, invokes a closes_toast action, or the app calls ToastHandle::dismiss.

Source

pub fn priority(self, priority: ToastPriority) -> Self

Set the queue priority. High / Urgent entries evict the oldest Normal entry when the slot pool is full; Urgent also forces Live::Assertive regardless of severity.

Source

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

Stable identity for the “progress toast updates in place” pattern. A subsequent enqueue whose Toast carries the same id as a still-live entry mutates that entry’s fields (severity, title/body, route, …) in place instead of appending a new toast — see ToastRegistry::enqueue’s update-in-place merge for the exact behaviour.

§Hazard: this id must be unique per logical operation, not just per call site

The merge matches on id ALONE — no route/window/audience check — and then OVERWRITES the existing entry’s route with the new toast’s resolved target. That’s intentional: it’s what lets a progress toast whose audience becomes known partway through retarget itself in place. But it also means that if TWO DIFFERENT windows (or two different audiences) each present a toast using the SAME id for what are, to the app, two DIFFERENT operations, the second enqueue finds the first window’s still-live entry, mutates its text/severity to the second operation’s, and steals its route out from under it — the first window’s toast is not dismissed, not callback’d, just silently overwritten and gone, while the second window’s operation ends up displayed under the wrong route besides.

teksilo deliberately does NOT make the dedup key route-aware (matching on (id, route) together) — that would break the intentional retargeting case above. So in a multi-window / multi-document app, do not reuse one static string id across windows for what is conceptually a per-document (or otherwise per-audience) operation — export, delete, save, etc. Fold the document/audience identity into the id yourself, e.g. format!("export-{work_id}") rather than a bare "export" constant, so two windows running the same kind of operation on two different documents never collide on one entry.

Source

pub fn on_click(self, f: impl Fn(&mut EventContext<'_>) + 'static) -> Self

Treat a click on the toast body as a meaningful action — the callback fires on tap. Cursor changes to Pointer over the body.

Source

pub fn on_dismiss( self, f: impl Fn(ToastDismissCause, &mut EventContext<'_>) + 'static, ) -> Self

Notification of dismissal. Fires exactly once per toast on any dismiss path (timer, action invocation, close click, escape, programmatic, host shutdown, slot-pool overflow).

Source

pub fn show_close_button(self, show: bool) -> Self

Show or hide the trailing close (×) button. Default true.

Source

pub fn closable_on_escape(self, allow: bool) -> Self

Whether pressing Escape while the toast is focused dismisses it. Default true. Set to false in apps that have a custom Escape-handling story (focus trap, modal-style toast).

Source

pub fn announcement(self, text: impl Into<LocalizedString>) -> Self

Override the screen-reader announcement text without changing the visible title. Useful when the visible title is iconic (“3”) but the spoken text needs context (“3 unread messages”).

Source

pub fn archive(self, archive: bool) -> Self

Whether this toast is added to the persistent archive that drives NotificationLog. Default true. Set false for noise-suppressing transient notifications like quick “Copied!” feedback.

Source

pub fn style(self, style: impl ToastStyle) -> Self

Override the visual chrome for this toast instance. Takes precedence over the theme-wide style_slots.toast slot and the built-in RecipeToastStyle default.

Source

pub fn target(self, audience: ToastAudience) -> Self

Route this toast to every window currently assigned audience (via ToastRegistry::set_window_audience), instead of the default origin-window. Overrides any previous .target() / .broadcast() call — last setter wins.

Source

pub fn broadcast(self) -> Self

Route this toast to every window, unconditionally — for genuinely app-wide messages (a data-loss warning, an update available notice) rather than one window’s concern. Overrides any previous .target() call — last setter wins.

Source

pub fn present(self, ctx: &mut EventContext<'_>) -> ToastHandle

Submit the toast through the installed ToastHost. Equivalent to ctx.show_toast(self). Returns a ToastHandle for programmatic control. If install_toast was not called the returned handle is in the “dropped” state (is_alive returns false) and a one-shot stderr warning fires explaining the omission.

Trait Implementations§

Source§

impl Debug for Toast

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Toast

§

impl !Send for Toast

§

impl !Sync for Toast

§

impl !UnwindSafe for Toast

§

impl Freeze for Toast

§

impl Unpin for Toast

§

impl UnsafeUnpin 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
§

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,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more