diff --git a/src/wrappers/builder.rs b/src/wrappers/builder.rs index d5e9421..548be7a 100644 --- a/src/wrappers/builder.rs +++ b/src/wrappers/builder.rs @@ -19,6 +19,29 @@ impl<'a> NotificationBuilder<'a> { /// # 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> { + /// 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(()) + /// } + /// + /// ``` pub fn new( summary: &str, body: T, @@ -41,6 +64,17 @@ impl<'a> NotificationBuilder<'a> { /// /// # Errors /// This function can return LibnotifyError::{NulError} + /// + /// # Example + /// ```ignore(Small example) + /// let notification_builder = NotificationBuilder::new( + /// "Remember about your coffee!", + /// "Only idiots forget about coffee!", + /// None, + /// &ctx, + /// )? + /// .set_app_name("Other app name"); + /// ``` pub fn set_app_name>>( mut self, app_name: T, @@ -56,6 +90,17 @@ impl<'a> NotificationBuilder<'a> { /// /// # Errors /// This function can return LibnotifyError::{NulError} + /// + /// # Example + /// ```ignore(Small example) + /// let notification_builder = NotificationBuilder::new( + /// "Remember about your coffee!", + /// "Only idiots forget about coffee!", + /// None, + /// &ctx, + /// )? + /// .set_app_icon("STOCK-HOME")?; + /// ``` pub fn set_app_icon>>( mut self, app_icon: T, @@ -91,6 +136,25 @@ impl<'a> NotificationBuilder<'a> { } /// Set timeout until close + /// + /// # Example + /// ``` + /// use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext}; + /// + /// fn main() -> Result<(), Box> { + /// 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(()) + /// } + /// ``` pub fn set_timeout>>(mut self, timeout: T) -> Self { if let Some(timeout) = timeout.into() { self.notification.set_timeout(timeout); @@ -100,6 +164,25 @@ impl<'a> NotificationBuilder<'a> { } /// Set notification urgency level + /// + /// # Example + /// ``` + /// use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext}; + /// + /// fn main() -> Result<(), Box> { + /// 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(()) + /// } + /// ``` pub fn set_urgency>>(mut self, urgency: T) -> Self { if let Some(urgency) = urgency.into() { self.notification.set_urgency(urgency); @@ -112,6 +195,28 @@ impl<'a> NotificationBuilder<'a> { /// /// # Errors /// This function can return LibnotifyError::NulError + /// + /// # Example + /// ``` + /// + /// use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext}; + /// + /// fn main() -> Result<(), Box> { + /// 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(()) + /// } + /// ``` pub fn add_action( mut self, action: &str, @@ -131,6 +236,31 @@ impl<'a> NotificationBuilder<'a> { /// /// # Errors /// This function can return LibnotifyError::{GerrorError, AllocationError} + /// + /// # Example + /// ```no_run(No notification daemon on CI) + /// use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext}; + /// + /// /// Builder is recommended way to interact with libnotify notifications + /// + /// fn main() -> Result<(), Box> { + /// 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(()) + /// } + /// ``` pub fn show(&self) -> Result<(), LibnotifyError> { self.notification.show()?; Ok(()) @@ -142,6 +272,31 @@ impl<'a> NotificationBuilder<'a> { /// /// # Errors /// This function can return LibnotifyError::{GerrorError, AllocationError} + /// + /// # Example + /// ```no_run(No notification daemon on CI) + /// use libnotify_rs::{builder::NotificationBuilder, context::LibnotifyContext}; + /// + /// /// Builder is recommended way to interact with libnotify notifications + /// + /// fn main() -> Result<(), Box> { + /// 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(()) + /// } + /// ``` pub fn close(&self) -> Result<(), LibnotifyError> { self.notification.close()?; Ok(())