Skip to main content

toast

Macro toast 

Source
macro_rules! toast {
    ($widget:expr, $message:expr $(,)?) => { ... };
    ($widget:expr, $message:expr, $($tail:tt)+) => { ... };
}
Expand description

Show a toast with the given message on an ancestor of widget.

The simplest way to use this macro is for displaying a simple message. It can be anything that implements AsRef<str>.

use gettextts::gettext;

use crate::toast;

toast!(widget, gettext("Something happened"));

This macro also supports replacing named variables with their value. It supports both the var and the var = expr syntax. The variable value must implement ToString.

use gettextts::gettext;

use crate::toast;

toast!(
    widget,
    gettext("Error number {n}: {msg}"),
    n = error_nb.to_string(),
    msg,
);

To add Pills to the toast, you can precede a type that implements PillSource with @.

use gettextts::gettext;
use crate::toast;
use crate::session::{Room, User};

let room = Room::new(session, room_id);
let member = Member::new(room, user_id);

toast!(
    widget,
    gettext("Could not contact {user} in {room}"),
    @user = member,
    @room,
);

For this macro to work, the widget must have one of these ancestors that can show toasts:

  • ToastableDialog
  • AdwPreferencesDialog
  • AdwPreferencesWindow
  • Window