Notification

Struct Notification 

Source
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 windows crate. This is the default.
  • The winrt-toast crate implementation is enabled by the feature winrt-toast. This crate provides additional features and controls.

Implementations§

Source§

impl Notification

Source

pub fn new_with_text(text: &str) -> Result<Self>

Construct from a string.

Source

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}
Source

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}
Source

pub fn inner(&self) -> &Toast

The inner winrt_toast::Toast.

Available only when the “winrt-toast” feature is enabled.

Source

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§

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.
Source§

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