Struct tauri_winrt_notification::Toast

source ·
pub struct Toast { /* private fields */ }

Implementations§

source§

impl Toast

source

pub const POWERSHELL_APP_ID: &'static str = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\ \\WindowsPowerShell\\v1.0\\powershell.exe"

This can be used if you do not have a AppUserModelID.

However, the toast will erroniously report its origin as powershell.

source

pub fn new(app_id: &str) -> Toast

Constructor for the toast builder.

app_id is the running application’s AppUserModelID.

If the program you are using this in was not installed, use Toast::POWERSHELL_APP_ID for now

Examples found in repository?
examples/sound_str.rs (line 9)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 12)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 11)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 12)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/image.rs (line 10)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn title(self, content: &str) -> Toast

Sets the title of the toast.

Will be white. Supports Unicode ✓

Examples found in repository?
examples/sound_str.rs (line 10)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 13)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 12)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 13)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/image.rs (line 17)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn text1(self, content: &str) -> Toast

Add/Sets the first line of text below title.

Will be grey. Supports Unicode ✓

Examples found in repository?
examples/sound_str.rs (line 11)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 14)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 13)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 14)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/image.rs (line 18)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn text2(self, content: &str) -> Toast

Add/Sets the second line of text below title.

Will be grey. Supports Unicode ✓

Examples found in repository?
examples/image.rs (line 19)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn duration(self, duration: Duration) -> Toast

Set the length of time to show the toast

Examples found in repository?
examples/sound_str.rs (line 13)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 15)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 15)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 15)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
source

pub fn scenario(self, scenario: Scenario) -> Toast

Set the scenario of the toast

The system keeps the notification on screen until the user acts upon/dismisses it. The system also plays the suitable notification sound as well.

source

pub fn icon(self, source: &Path, crop: IconCrop, alt_text: &str) -> Toast

Set the icon shown in the upper left of the toast

The default is determined by your app id. If you are using the powershell workaround, it will be the powershell icon

Examples found in repository?
examples/image.rs (lines 12-16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn hero(self, source: &Path, alt_text: &str) -> Toast

Add/Set a Hero image for the toast.

This will be above the toast text and the icon.

Examples found in repository?
examples/image.rs (line 11)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn image(self, source: &Path, alt_text: &str) -> Toast

Add an image to the toast

May be done many times. Will appear below text.

Examples found in repository?
examples/image.rs (line 20)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn sound(self, src: Option<Sound>) -> Toast

Set the sound for the toast or silence it

Default is Sound::IM

Examples found in repository?
examples/sound_str.rs (line 12)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 16)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 14)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 16)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/image.rs (line 22)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}
source

pub fn on_activated<F: FnMut() -> Result<()> + Send + 'static>( self, f: F ) -> Self

Examples found in repository?
examples/simple.rs (line 16)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
source

pub fn show(&self) -> Result<()>

Display the toast on the screen

Examples found in repository?
examples/sound_str.rs (line 14)
8
9
10
11
12
13
14
15
16
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound("Alarm5".try_into().ok())
        .duration(Duration::Short)
        .show()
        .expect("unable to send notification");
}
More examples
Hide additional examples
examples/reuse_toast.rs (line 19)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound);

    toast
        .show()
        // silently consume errors
        .expect("notification failed");

    toast
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/simple.rs (line 17)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("Look at this flip!")
        .text1("(╯°□°)╯︵ ┻━┻")
        .sound(Some(Sound::SMS))
        .duration(Duration::Short)
        .on_activated(handle_notification_click)
        .show()
        .expect("unable to send notification");
    println!("Waiting 10 seconds for the notification to be clicked...");
    sleep(StdDuration::from_secs(10));
    println!("The notification wasn't clicked!");
}
examples/reuse_arguments.rs (line 17)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    let duration = Duration::Short;
    let sound = Some(Sound::SMS);

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("first toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");

    Toast::new(Toast::POWERSHELL_APP_ID)
        .title("another toast")
        .text1("line1")
        .duration(duration)
        .sound(sound)
        .show()
        // silently consume errors
        .expect("notification failed");
}
examples/image.rs (line 23)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    Toast::new("application that needs a toast with an image")
        .hero(Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
        .icon(
            Path::new("c:/this/style/works/too/image.png"),
            IconCrop::Circular,
            "alt text",
        )
        .title("Lots of pictures here")
        .text1("One above the text as the hero")
        .text2("One to the left as an icon, and several below")
        .image(Path::new("c:/photos/sun.png"), "the sun")
        .image(Path::new("c:/photos/moon.png"), "the moon")
        .sound(None) // will be silent
        .show()
        .expect("notification failed");
}

Auto Trait Implementations§

§

impl Freeze for Toast

§

impl RefUnwindSafe for Toast

§

impl !Send for Toast

§

impl !Sync for Toast

§

impl Unpin 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.