Struct Notification

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

A notification dialog, which can be used to send a notification to the user through the system’s API.

§Examples

use nvdialog_rs::Notification;

let mut notification = Notification::new("Hello world!", "This is a notification.");
notification.send();

Implementations§

Source§

impl Notification

Source

pub fn new<S: AsRef<str>>( title: S, msg: S, kind: NotificationKind, ) -> Result<Self, Error>

Constructs a new Notification object with the given title, message and kind of notification.

§Arguments
  • title: A string for the title / summary of the notification.
  • msg: The actual body of the notification.
  • kind: The kind of the notification, see NotificationKind.
§Errors

Returns an Error of type OutOfMemory if NvDialog’s allocation failed.

§Examples
use nvdialog_rs::{Notification, NotificationKind};
let notification = Notification::new("Hello", "This is a notification", NotificationKind::Simple);
§FFI

Correspons to nvd_notification_new.

Examples found in repository?
examples/notification.rs (lines 29-33)
27fn main() {
28    nvdialog_rs::init().expect("Failed to initialize NvDialog!");
29    let mut notification = Notification::new(
30        "Notification from Rust!",
31        "Here's a notification using nvdialog-rs!",
32        NotificationKind::Simple,
33    )
34    .expect("Unable to construct notification");
35    notification.send();
36}
Source

pub fn add_action<S: AsRef<str>>(&mut self, name: S, val: i32, ptr: &mut i32)

The add_action function in Rust adds a notification action with a specified name, value, and pointer.

Arguments:

  • [name]: A string that that represents the name of an action to be added.
  • [val]: The value to save in the address pointed to by [ptr]
  • [ptr]: A pointer to the variable to save the response to
Source

pub fn send(&mut self)

Sends the notification to the desktop notification system. If the notification has already been shown or sent, calling this method again will have no effect.

§Examples
use nvdialog_rs::{Notification, NotificationKind};

let mut notification = Notification::new("Title", "Body", NotificationKind::Simple)
    .expect("Failed to create notification");

// Send the notification
notification.send();
§FFI

Corresponds to nvd_send_notification.

Examples found in repository?
examples/notification.rs (line 35)
27fn main() {
28    nvdialog_rs::init().expect("Failed to initialize NvDialog!");
29    let mut notification = Notification::new(
30        "Notification from Rust!",
31        "Here's a notification using nvdialog-rs!",
32        NotificationKind::Simple,
33    )
34    .expect("Unable to construct notification");
35    notification.send();
36}

Trait Implementations§

Source§

impl Drop for Notification

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.