Toast

Struct Toast 

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

Implementations§

Source§

impl Toast

Source

pub fn new() -> Self

Creates an empty toast.

Examples found in repository?
examples/sample.rs (line 18)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn header(&mut self, header: Header) -> &mut Toast

Add a Header to this toast.

Source

pub fn text1<T: Into<Text>>(&mut self, text: T) -> &mut Toast

The first text element, usually the title.

§Example
// You can use anything that is Into<String>
toast.text1("text");

// Or you can use a `Text`
toast.text1(
    Text::new("text").with_placement(TextPlacement::Attribution)
);
Examples found in repository?
examples/sample.rs (line 31)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn text2<T: Into<Text>>(&mut self, text: T) -> &mut Toast

The second text element, usually the body.

Examples found in repository?
examples/sample.rs (line 32)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn text3<T: Into<Text>>(&mut self, text: T) -> &mut Toast

The third text element, usually the body or attribution.

Examples found in repository?
examples/sample.rs (line 33)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn image(&mut self, id: u8, image: Image) -> &mut Toast

Add an image with the corresponding ID to the toast.

§ID

The image element in the toast template that this image is intended for. If a template has only one image, then this value is 1. The number of available image positions is based on the template definition.

Examples found in repository?
examples/sample.rs (line 34)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn input(&mut self, input: Input) -> &mut Toast

Add an input field to the toast.

Examples found in repository?
examples/sample.rs (lines 38-42)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn selection(&mut self, selection: Selection) -> &mut Toast

Add a selection field to the toast.

Examples found in repository?
examples/sample.rs (line 43)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn action(&mut self, action: Action) -> &mut Toast

Add a new action to the toast.

Examples found in repository?
examples/sample.rs (line 46)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn tag(&mut self, tag: impl Into<String>) -> &mut Toast

Examples found in repository?
examples/sample.rs (line 30)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn group(&mut self, group: impl Into<String>) -> &mut Toast

Source

pub fn remote_id(&mut self, remote_id: impl Into<String>) -> &mut Toast

Set a remote id for the notification that enables the system to correlate this notification with another one generated on another device.

Source

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

Set the scenario of this toast.

The scenario adjusts a few behaviors to create a consistent and unified user experience.

Source

pub fn launch(&mut self, launch: impl Into<String>) -> &mut Toast

A string that is passed to the application when it is activated by the toast.

The format and contents of this string are defined by the app for its own use. When the user taps or clicks the toast to launch its associated app, the launch string provides the context to the app that allows it to show the user a view relevant to the toast content, rather than launching in its default way.

Source

pub fn duration(&mut self, duration: ToastDuration) -> &mut Toast

The amount of time the toast should display.

Examples found in repository?
examples/sample.rs (line 36)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}
Source

pub fn use_button_style(&mut self) -> &mut Toast

Enable the use of button style for this toast.

Source

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

Set the expiration time of this toast, starting from the moment it is shown.

After expiration, the toast will be removed from the Notification Center.

Source

pub fn audio(&mut self, audio: Audio) -> &mut Toast

Set the audio for this toast.

The audio will play when the toast is shown.

Examples found in repository?
examples/sample.rs (line 37)
15fn main() -> Result<()> {
16    let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18    let mut toast = Toast::new();
19
20    let hero_image =
21        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22            .with_placement(ImagePlacement::Hero);
23
24    let icon_image =
25        Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26            .with_placement(ImagePlacement::AppLogoOverride)
27            .with_hint_crop(ImageHintCrop::Circle);
28
29    toast
30        .tag("example")
31        .text1("Title")
32        .text2(Text::new("Body"))
33        .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34        .image(1, hero_image)
35        .image(2, icon_image)
36        .duration(ToastDuration::Long)
37        .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38        .input(
39            Input::new("box", InputType::Selection)
40                .with_title("Select an option")
41                .with_default_input("breakfast"),
42        )
43        .selection(Selection::new("breakfast", "Breakfast"))
44        .selection(Selection::new("lunch", "Lunch"))
45        .selection(Selection::new("dinner", "Dinner"))
46        .action(Action::new("Send", "send", "").with_input_id("box"))
47        .action(Action::new("Dismiss", "dismiss", ""));
48
49    // Clone the action_take atomic bool for the closures
50    // This is necessary because the closures are Fn/FnMut,
51    // and we need to be able to modify the action_take bool
52    // from within the closures
53    let action_take = Arc::new(AtomicBool::new(false));
54    let action_clone = Arc::clone(&action_take);
55    let dismiss_clone = Arc::clone(&action_take);
56
57    fn handle_activated_action(action: Option<ActivatedAction>) {
58        match action {
59            Some(action) => {
60                let message = format!(
61                    "You clicked on {}{}!",
62                    action.arg,
63                    action
64                        .values
65                        .get(&action.input_id.unwrap_or_default())
66                        .map_or(String::new(), |value| format!(", input = {value}"))
67                );
68                println!("{message}");
69            }
70            None => println!("You clicked me!"),
71        }
72    }
73
74    manager
75        .on_activated(Some("box"), move |action| {
76            handle_activated_action(action);
77            action_clone.store(true, Ordering::SeqCst);
78        })
79        .on_dismissed(move |reason| {
80            match reason {
81                Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82                Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83                    println!("ApplicationHidden")
84                }
85                Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86                Ok(_r) => println!("Unknown dismissal reason"),
87                Err(e) => eprintln!("Error: {e:?}"),
88            }
89            dismiss_clone.store(true, Ordering::SeqCst);
90        })
91        .on_failed(|e| eprintln!("Error: {e:?}"))
92        .show(&toast)
93        .expect("Failed to show toast");
94
95    // Wait for the user to interact with the toast
96    let time_instant = Instant::now();
97    while time_instant.elapsed() < Duration::from_secs(25) {
98        if action_take.load(Ordering::SeqCst) {
99            break;
100        }
101        sleep(Duration::from_millis(100));
102    }
103
104    Ok(())
105}

Trait Implementations§

Source§

impl Clone for Toast

Source§

fn clone(&self) -> Toast

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Toast

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Toast

Source§

fn default() -> Toast

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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