pub struct NotificationBuilder<'a> { /* private fields */ }Expand description
Higher level abstraction of Notification. Allow for builder pattern notification construction.
Requires LibnotifyContext
Implementations§
Source§impl<'a> NotificationBuilder<'a>
impl<'a> NotificationBuilder<'a>
Sourcepub fn new<T, Y>(
summary: &str,
body: T,
icon: Y,
context: &'a LibnotifyContext,
) -> Result<Self, Box<dyn Error>>
pub fn new<T, Y>( summary: &str, body: T, icon: Y, context: &'a LibnotifyContext, ) -> Result<Self, Box<dyn Error>>
Create new NotificationBuilder, with given context.
§Errors
This function can return LibnotifyError::{NewNotificationError, NulError}
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
// Builder is recommended way to interact with libnotify notifications
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?;
// you don't need to uninitialize libnotify, cause context already does that!
Ok(())
}
Sourcepub fn set_app_name<T: Into<Option<&'a str>>>(
self,
app_name: T,
) -> Result<Self, LibnotifyError>
pub fn set_app_name<T: Into<Option<&'a str>>>( self, app_name: T, ) -> Result<Self, LibnotifyError>
Sourcepub fn set_app_icon<T: Into<Option<&'a str>>>(
self,
app_icon: T,
) -> Result<Self, LibnotifyError>
pub fn set_app_icon<T: Into<Option<&'a str>>>( self, app_icon: T, ) -> Result<Self, LibnotifyError>
Sourcepub fn set_category<T: Into<Option<&'a str>>>(
self,
category: T,
) -> Result<Self, LibnotifyError>
pub fn set_category<T: Into<Option<&'a str>>>( self, category: T, ) -> Result<Self, LibnotifyError>
Sets category for this specific notification
§Errors
This function can return LibnotifyError::{NulError}
Sourcepub fn set_hint(
self,
key: &str,
value: HintValue,
) -> Result<Self, LibnotifyError>
pub fn set_hint( self, key: &str, value: HintValue, ) -> Result<Self, LibnotifyError>
Set hint for this specific notification
§Errors
This function can return LibnotifyError::{NulError, AllocationError}
Sourcepub fn set_timeout<T: Into<Option<Timeout>>>(self, timeout: T) -> Self
pub fn set_timeout<T: Into<Option<Timeout>>>(self, timeout: T) -> Self
Set timeout until close
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?
.set_timeout(libnotify_rs::api::notification::Timeout::Never);
Ok(())
}Sourcepub fn set_urgency<T: Into<Option<Urgency>>>(self, urgency: T) -> Self
pub fn set_urgency<T: Into<Option<Urgency>>>(self, urgency: T) -> Self
Set notification urgency level
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?
.set_urgency(libnotify_rs::api::notification::Urgency::Critical);
Ok(())
}Sourcepub fn add_action<F>(
self,
action: &str,
label: &str,
callback: F,
) -> Result<Self, LibnotifyError>
pub fn add_action<F>( self, action: &str, label: &str, callback: F, ) -> Result<Self, LibnotifyError>
Add callback
§Errors
This function can return LibnotifyError::NulError
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?
.add_action("default", "super cool action", |action| {
println!("Action: {} was run!", action);
});
Ok(())
}Sourcepub fn show(&self) -> Result<(), LibnotifyError>
pub fn show(&self) -> Result<(), LibnotifyError>
Show notification
Uses &self borrow, so you can use this object later, after showing.
§Errors
This function can return LibnotifyError::{GerrorError, AllocationError}
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
/// Builder is recommended way to interact with libnotify notifications
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?
.set_urgency(libnotify_rs::api::notification::Urgency::Critical)
.set_timeout(libnotify_rs::api::notification::Timeout::Never)
.set_category("Coffee")?;
notification_builder.show()?;
Ok(())
}Sourcepub fn close(&self) -> Result<(), LibnotifyError>
pub fn close(&self) -> Result<(), LibnotifyError>
Close notification synchronously.
Uses &self borrow, so you can use this object later, after closing.
§Errors
This function can return LibnotifyError::{GerrorError, AllocationError}
§Example
use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext};
/// Builder is recommended way to interact with libnotify notifications
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = LibnotifyContext::new("Coffee addicted reminder")?; // builder requires context
let notification_builder = NotificationBuilder::new(
"Remember about your coffee!",
"Only idiots forget about coffee!",
None,
&ctx,
)?
.set_urgency(libnotify_rs::api::notification::Urgency::Critical)
.set_timeout(libnotify_rs::api::notification::Timeout::Never)
.set_category("Coffee")?;
notification_builder.show()?;
notification_builder.close()?;
Ok(())
}