Toast

Struct 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/simple.rs (line 9)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 8)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 12)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
examples/image.rs (line 9)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
Source

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

Sets the title of the toast.

Will be white. Supports Unicode ✓

Examples found in repository?
examples/simple.rs (line 10)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 9)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 13)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
examples/image.rs (line 16)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
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/simple.rs (line 11)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 10)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 14)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
examples/image.rs (line 17)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
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 18)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
Source

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

Set the length of time to show the toast

Examples found in repository?
examples/simple.rs (line 13)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 11)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 15)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
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 11-15)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
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 10)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
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 19)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
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/simple.rs (line 12)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 12)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 16)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
examples/image.rs (line 21)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}
Source

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

Display the toast on the screen

Examples found in repository?
examples/simple.rs (line 14)
8fn main() {
9    Toast::new(Toast::POWERSHELL_APP_ID)
10        .title("Look at this flip!")
11        .text1("(╯°□°)╯︵ ┻━┻")
12        .sound(Some(Sound::SMS))
13        .duration(Duration::Short)
14        .show()
15        .expect("unable to send notification");
16}
More examples
Hide additional examples
examples/reuse_toast.rs (line 15)
4fn main() {
5    let duration = Duration::Short;
6    let sound = Some(Sound::SMS);
7
8    let toast = Toast::new(Toast::POWERSHELL_APP_ID)
9        .title("first toast")
10        .text1("line1")
11        .duration(duration)
12        .sound(sound);
13
14    toast
15        .show()
16        // silently consume errors
17        .expect("notification failed");
18
19    toast
20        .show()
21        // silently consume errors
22        .expect("notification failed");
23}
examples/reuse_arguments.rs (line 17)
8fn main() {
9    let duration = Duration::Short;
10    let sound = Some(Sound::SMS);
11
12    Toast::new(Toast::POWERSHELL_APP_ID)
13        .title("first toast")
14        .text1("line1")
15        .duration(duration)
16        .sound(sound)
17        .show()
18        // silently consume errors
19        .expect("notification failed");
20
21    Toast::new(Toast::POWERSHELL_APP_ID)
22        .title("another toast")
23        .text1("line1")
24        .duration(duration)
25        .sound(sound)
26        .show()
27        // silently consume errors
28        .expect("notification failed");
29}
examples/image.rs (line 22)
8fn main() {
9    Toast::new("application that needs a toast with an image")
10        .hero(&Path::new("C:\\absolute\\path\\to\\image.jpeg"), "alt text")
11        .icon(
12            &Path::new("c:/this/style/works/too/image.png"),
13            IconCrop::Circular,
14            "alt text",
15        )
16        .title("Lots of pictures here")
17        .text1("One above the text as the hero")
18        .text2("One to the left as an icon, and several below")
19        .image(&Path::new("c:/photos/sun.png"), "the sun")
20        .image(&Path::new("c:/photos/moon.png"), "the moon")
21        .sound(None) // will be silent
22        .show()
23        .expect("notification failed");
24}

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

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.