pub struct Notification { /* private fields */ }Expand description
Abstracted notification.
This struct is to provide a hook point before the notification is shown.
Please see ToastLoggerBuilder::create_notification for
how to add the hook.
§Underlying Implementations
There are two underlying implementations.
- An internal implementation using the
windowscrate. This is the default. - The
winrt-toastcrate implementation is enabled by the featurewinrt-toast. This crate provides additional features and controls.
Implementations§
Source§impl Notification
impl Notification
Sourcepub fn new_with_text(text: &str) -> Result<Self>
pub fn new_with_text(text: &str) -> Result<Self>
Construct from a string.
Sourcepub fn new_with_records(records: &[BufferedRecord]) -> Result<Self>
pub fn new_with_records(records: &[BufferedRecord]) -> Result<Self>
Construct from a list of BufferedRecord.
Examples found in repository?
examples/expire.rs (line 19)
5pub fn main() -> anyhow::Result<()> {
6 let args: Vec<String> = env::args().skip(1).collect();
7 let duration = if args.is_empty() {
8 Duration::ZERO
9 } else {
10 Duration::from_secs(args[0].parse()?)
11 };
12
13 let mut builder = ToastLogger::builder();
14 let message = if duration.is_zero() {
15 "This message shouldn't expire".into()
16 } else {
17 let message = format!("This message should expire in {duration:?}.");
18 builder.create_notification(move |records| {
19 let mut notification = Notification::new_with_records(records)?;
20 notification.expires_in(duration)?;
21 Ok(notification)
22 });
23 message
24 };
25 builder.max_level(log::LevelFilter::Info).init()?;
26
27 log::info!("{}", message);
28 Ok(())
29}Sourcepub fn expires_in(&mut self, duration: Duration) -> Result<()>
pub fn expires_in(&mut self, duration: Duration) -> Result<()>
Set the expirations of this notification.
Please see ToastNotification.ExpirationTime.
Examples found in repository?
examples/expire.rs (line 20)
5pub fn main() -> anyhow::Result<()> {
6 let args: Vec<String> = env::args().skip(1).collect();
7 let duration = if args.is_empty() {
8 Duration::ZERO
9 } else {
10 Duration::from_secs(args[0].parse()?)
11 };
12
13 let mut builder = ToastLogger::builder();
14 let message = if duration.is_zero() {
15 "This message shouldn't expire".into()
16 } else {
17 let message = format!("This message should expire in {duration:?}.");
18 builder.create_notification(move |records| {
19 let mut notification = Notification::new_with_records(records)?;
20 notification.expires_in(duration)?;
21 Ok(notification)
22 });
23 message
24 };
25 builder.max_level(log::LevelFilter::Info).init()?;
26
27 log::info!("{}", message);
28 Ok(())
29}Sourcepub fn inner(&self) -> &Toast
pub fn inner(&self) -> &Toast
The inner winrt_toast::Toast.
Available only when the “winrt-toast” feature is enabled.
Sourcepub fn inner_mut(&mut self) -> &mut Toast
pub fn inner_mut(&mut self) -> &mut Toast
The mutable inner winrt_toast::Toast.
Available only when the “winrt-toast” feature is enabled.
Auto Trait Implementations§
impl Freeze for Notification
impl RefUnwindSafe for Notification
impl Send for Notification
impl Sync for Notification
impl Unpin for Notification
impl UnwindSafe for Notification
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
Mutably borrows from an owned value. Read more