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
impl Toast
Sourcepub fn info(title: impl Into<LocalizedString>) -> Self
pub fn info(title: impl Into<LocalizedString>) -> Self
Info-severity toast (status confirmation, neutral notice).
Sourcepub fn success(title: impl Into<LocalizedString>) -> Self
pub fn success(title: impl Into<LocalizedString>) -> Self
Success-severity toast (“Saved”, “Connected”, “Build finished”).
Sourcepub fn error(title: impl Into<LocalizedString>) -> Self
pub fn error(title: impl Into<LocalizedString>) -> Self
Error-severity toast. Defaults to Live::Assertive.
Sourcepub fn loading(title: impl Into<LocalizedString>) -> Self
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.
Sourcepub fn body(self, text: impl Into<LocalizedString>) -> Self
pub fn body(self, text: impl Into<LocalizedString>) -> Self
Optional secondary line below the title.
Sourcepub fn leading(self, widget: impl Widget + 'static) -> Self
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.
Sourcepub fn action(self, action: ToastAction) -> Self
pub fn action(self, action: ToastAction) -> Self
Append a ToastAction (link or button) to the toast.
Sourcepub fn primary_action(
self,
label: impl Into<LocalizedString>,
on_invoke: impl Fn(&mut EventContext<'_>) + 'static,
) -> Self
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)).
Sourcepub fn auto_dismiss_after(self, duration: Duration) -> Self
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.
Sourcepub fn persistent(self) -> Self
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.
Sourcepub fn priority(self, priority: ToastPriority) -> Self
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.
Sourcepub fn id(self, id: impl Into<String>) -> Self
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.
Sourcepub fn on_click(self, f: impl Fn(&mut EventContext<'_>) + 'static) -> Self
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.
Sourcepub fn on_dismiss(
self,
f: impl Fn(ToastDismissCause, &mut EventContext<'_>) + 'static,
) -> Self
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).
Show or hide the trailing close (×) button. Default true.
Sourcepub fn closable_on_escape(self, allow: bool) -> Self
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).
Sourcepub fn announcement(self, text: impl Into<LocalizedString>) -> Self
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”).
Sourcepub fn archive(self, archive: bool) -> Self
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.
Sourcepub fn style(self, style: impl ToastStyle) -> Self
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.
Sourcepub fn target(self, audience: ToastAudience) -> Self
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.
Sourcepub fn broadcast(self) -> Self
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.
Sourcepub fn present(self, ctx: &mut EventContext<'_>) -> ToastHandle
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§
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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