From b6e19b531368f6a968c72f2a1b905b052940bf16 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:07:59 +0200 Subject: [PATCH 01/26] chore: add warnings about missing errors docs --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 255dc50..a5d2003 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![warn(missing_docs)] +#![warn(clippy::missing_errors_doc)] #[cfg(not(target_os = "linux"))] compile_error!("Libnotify-rs only supports linux"); From 2832dff7f1b18fd33d171d8a678918650a3eca2d Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:17:10 +0200 Subject: [PATCH 02/26] docs: add example to init --- src/api/functions.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/api/functions.rs b/src/api/functions.rs index 3b73133..face787 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -9,10 +9,26 @@ use super::libnotify::*; *(what a cool section comment) */ -/// Initialized libnotify. This must be called before any other functions. +/// Initializes libnotify. This must be called before any other functions. /// /// Starting from 0.8, if the provided app_name is NULL, libnotify will try to figure it out from the running application. Before it was not allowed, and was causing libnotify not to be initialized. /// +/// # Example +/// +/// ``` +/// use libnotify_rs::api::{ +/// functions::init, +/// notification:: Notification, +/// }; +/// +/// fn main() -> Result<(), Box> { +/// init("Test app")?; // we need to init libnotify __before__ any other libnotify code +/// let notification = Notification::new("Test", None, None)?; // Some libnotify call +/// Ok(()) +/// } +/// +/// ``` +/// /// # Errors /// This function can return LibnotifyError::{InitError, NulError} pub fn init<'a, T>(app_name: T) -> Result<(), LibnotifyError> From 5c71686b176324c6913e24757d7df2ec55a9ce38 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:21:08 +0200 Subject: [PATCH 03/26] docs: add example to uninit --- src/api/functions.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index face787..edc5d17 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -54,6 +54,19 @@ where /// Uninitializes libnotify. /// /// This should be called when the program no longer needs libnotify for the rest of its lifecycle, typically just before exitting. +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{init, uninit}; +/// +/// fn main() -> Result<(), Box> { +/// init("Test app")?; +/// // let notify = ... +/// uninit(); // __always__ uninit libnotify after use +/// Ok(()) +/// } +/// +/// ``` pub fn uninit() { unsafe { notify_uninit(); From be5d8e098c969500038fc26ea333a73cb1ca6477 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:22:26 +0200 Subject: [PATCH 04/26] docs: add doctest to is_inited --- src/api/functions.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index edc5d17..d0d1497 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -74,6 +74,20 @@ pub fn uninit() { } /// Gets whether or not libnotify is initialized. +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{init, is_initted}; +/// +/// fn main() -> Result<(), Box> { +/// if !is_initted() { // useful for conditional initing +/// init("Test app")?; +/// } +/// +/// Ok(()) +/// } +/// +/// ``` pub fn is_initted() -> bool { unsafe { notify_is_initted() != 0 } } From 6d1be544c5cee0a030756e5d5671baecd462fe3e Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:29:46 +0200 Subject: [PATCH 05/26] docs: add doctest to get_app_name --- src/api/functions.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index d0d1497..9316648 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -97,6 +97,20 @@ pub fn is_initted() -> bool { */ /// Gets the application name registered. +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{get_app_name, init}; +/// +/// fn main() -> Result<(), Box> { +/// let app_name = "Test app"; +/// init(app_name)?; +/// let app_name_gotten: String = get_app_name().ok_or::("No name gotten".into())?; +/// assert_eq!(app_name, app_name_gotten); +/// Ok(()) +/// } +/// +/// ``` pub fn get_app_name() -> Option { let app_name_c: *const std::os::raw::c_char = unsafe { notify_get_app_name() }; From b1a442b566efbd04c0b27d223928246047db017c Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:32:25 +0200 Subject: [PATCH 06/26] docs: add doctest to get_app_icon --- src/api/functions.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index 9316648..205e3cd 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -127,6 +127,20 @@ pub fn get_app_name() -> Option { /// Gets the application icon registered. /// Available since: 0.8.4 +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{get_app_icon, get_app_name, init, set_app_icon}; +/// +/// fn main() -> Result<(), Box> { +/// init("Test app")?; +/// let icon = "gimp"; +/// set_app_icon(icon)?; +/// let icon_gotten = get_app_icon().ok_or::("No app icon set".into())?; +/// assert_eq!(icon, icon_gotten); +/// Ok(()) +/// } +/// ``` pub fn get_app_icon() -> Option { let app_icon_c: *const std::os::raw::c_char = unsafe { notify_get_app_icon() }; From fe237ce0760faa93c6c481998360348dd7dc3ef6 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:35:55 +0200 Subject: [PATCH 07/26] docs: add doctest to get_server_caps --- src/api/functions.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index 205e3cd..b56ec27 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -157,6 +157,27 @@ pub fn get_app_icon() -> Option { /// Queries the server capabilities. /// Synchronously queries the server for its capabilities and returns them in a list. +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{self, uninit}; +/// +/// fn main() -> Result<(), Box> { +/// functions::init("Test app")?; +/// +/// if let Some(caps) = functions::get_server_caps() { +/// println!("=== Server caps ==="); +/// for s in caps { +/// println!("{}", s); +/// } +/// } else { +/// eprintln!("No server caps"); +/// } +/// +/// Ok(()) +/// } +/// +/// ``` pub fn get_server_caps() -> Option> { let mut vec: Vec = vec![]; From 221812e18dd2c6b609e6e41e00724c5ee64c8c72 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:37:08 +0200 Subject: [PATCH 08/26] docs: add doctest to get_server_info --- src/api/functions.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index b56ec27..00df23d 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -227,6 +227,41 @@ pub struct ServerInfo { /// Queries the server for information. /// Synchronously queries the server for its information, specifically, the name, vendor, server version, and the version of the notifications specification that it is compliant with. +/// +/// # Example +/// ``` +/// +/// use libnotify_rs::api::functions::{self, uninit}; +/// +/// fn main() -> Result<(), Box> { +/// functions::init("Test app")?; +/// +/// if let Some(info) = functions::get_server_info() { +/// println!("=== Server info ==="); +/// if let Some(name) = info.name { +/// println!("Server name: {}", name); +/// } +/// +/// if let Some(vendor) = info.vendor { +/// println!("Server vendor: {}", vendor); +/// } +/// +/// if let Some(version) = info.version { +/// println!("Server version: {}", version); +/// } +/// +/// if let Some(spec_version) = info.spec_version { +/// println!("Server spec version: {}", spec_version); +/// } +/// } else { +/// eprintln!("No server info"); +/// } +/// +/// uninit(); +/// +/// Ok(()) +/// } +/// ``` pub fn get_server_info() -> Option { let mut ret_name = std::ptr::null_mut() as *mut std::os::raw::c_char; let mut ret_vendor = std::ptr::null_mut() as *mut std::os::raw::c_char; From 1f0def6499ee3b45e8e2b6d34397f18b55e5fec2 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:38:46 +0200 Subject: [PATCH 09/26] docs: add doctest to set_app_name --- src/api/functions.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index 00df23d..47a6004 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -296,6 +296,19 @@ pub fn get_server_info() -> Option { /// /// # Errors /// This function can return LibnotifyError::NulError +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{get_app_name, init, set_app_name}; +/// +/// fn main() -> Result<(), Box> { +/// init("Test app")?; +/// let app_name = "morbius app"; +/// set_app_name(app_name)?; +/// assert_eq!(app_name, get_app_name().unwrap()); +/// Ok(()) +/// } +/// ``` pub fn set_app_name(app_name: &str) -> Result<(), LibnotifyError> { let app_name_c = std::ffi::CString::new(app_name)?; unsafe { notify_set_app_name(app_name_c.as_ptr()) }; From 4acf6a6b87e3195bc2e2c36466056af530166826 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:40:09 +0200 Subject: [PATCH 10/26] docs: add doctest to set_app_icon --- src/api/functions.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/functions.rs b/src/api/functions.rs index 47a6004..9a02b28 100644 --- a/src/api/functions.rs +++ b/src/api/functions.rs @@ -323,6 +323,19 @@ pub fn set_app_name(app_name: &str) -> Result<(), LibnotifyError> { /// /// # Errors /// This function can return LibnotifyError::NulError +/// +/// # Example +/// ``` +/// use libnotify_rs::api::functions::{get_app_icon, init, set_app_icon}; +/// +/// fn main() -> Result<(), Box> { +/// init("Test app")?; +/// let app_icon = "morbius app"; +/// set_app_icon(app_icon)?; +/// assert_eq!(app_icon, get_app_icon().unwrap()); +/// Ok(()) +/// } +/// ``` pub fn set_app_icon(app_icon: &str) -> Result<(), LibnotifyError> { let app_icon_c = std::ffi::CString::new(app_icon)?; unsafe { notify_set_app_icon(app_icon_c.as_ptr()) }; From db0f9b33a27c04626b745f7fe52184320ae00711 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:41:34 +0200 Subject: [PATCH 11/26] fix: lack of url to clap in docs --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a5d2003..c4a65ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ //! //! # Features //! -//! - clap – enables [clap] support for `Urgency` +//! - clap – enables [clap](https://docs.rs/clap/latest/clap/) support for `Urgency` //! #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] From 8e88f16912e8ec02457fcd01f2e2b801f5007f70 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:43:51 +0200 Subject: [PATCH 12/26] docs: add doctest to notification::new --- src/api/notification.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index a1e6831..87d747e 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -66,6 +66,23 @@ impl<'a> Notification { /// /// # Errors /// This function can return LibnotifyError::{NewNotificationError, NulError} + /// + /// # Example + /// ``` + /// + /// use libnotify_rs::api::{ + /// functions::{init, uninit}, + /// notification::Notification, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("Test app")?; + /// let notification = Notification::new("My notification", "Yap yap", None)?; + /// // ... + /// uninit(); + /// Ok(()) + /// } + /// ``` pub fn new(summary: &str, body: T, icon: Y) -> Result where T: Into>, From b83c75770a7a2b7bed90ed1edc7809ba4110120f Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:47:13 +0200 Subject: [PATCH 13/26] docs: add doctest to notification::add_action --- src/api/notification.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 87d747e..53a2ea4 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -111,6 +111,8 @@ impl<'a> Notification { /// Add callback to notification. /// + /// This function needs a [glib mainloop](https://docs.gtk.org/glib/main-loop.html) + /// /// # Args /// `action` – action identifier. `default` will work for most use cases. Other text will be /// displayed as button names. @@ -121,6 +123,39 @@ impl<'a> Notification { /// /// # Errors /// This function can return LibnotifyError::NulError + /// + /// # Example + /// ```no_run(There's no notification deamon on CI and no one to click the notification) + /// use glib::MainLoop; + /// use libnotify_rs::{ + /// api::functions::{init, uninit}, + /// api::notification::Notification, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("Coffee reminder")?; + /// let mut notify = Notification::new("Drink coffee", "Click me when you're done drinking", None)?; + /// + /// // We need to have a glib main loop in order to receive callback actions + /// let main_loop = MainLoop::new(None, false); + /// let loop_clone = main_loop.clone(); + /// + /// notify.add_action("default", "I'm drinking!", move |action_name| { + /// println!("User drunk his coffee!"); + /// println!("Action was named: {}", action_name); + /// loop_clone.quit(); + /// })?; + /// + /// notify.show()?; + /// main_loop.run(); + /// + /// println!("Glib mainloop has ended"); + /// + /// uninit(); + /// + /// Ok(()) + /// } + /// ``` pub fn add_action( &mut self, action: &str, From 60026e6fea9003c9dc1f0660a47817a077eccb1c Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:49:37 +0200 Subject: [PATCH 14/26] docs: add doctest to notification::clear_actions --- src/api/notification.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 53a2ea4..118330c 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -188,6 +188,32 @@ impl<'a> Notification { } /// Clears all actions from the notification + /// + /// # Example + /// ``` + /// use libnotify_rs::api::{ + /// functions::{init, uninit}, + /// notification::Notification, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("Test app")?; + /// let mut notification = Notification::new("My notification", "Yap yap", None)?; + /// notification.add_action("default", "yap", |action| { + /// // do stuff + /// })?; + /// + /// notification.add_action("click", "yappers", |action| { + /// // do some other stuff + /// })?; + /// + /// notification.clear_actions(); // now there are no callbacks! + /// + /// uninit(); + /// Ok(()) + /// } + /// ``` + /// pub fn clear_actions(&mut self) { unsafe { notify_notification_clear_actions(self.inner) } } From 0503fa8e28584038817ecd1e0bd6821ad04721a2 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:54:27 +0200 Subject: [PATCH 15/26] docs: add url to icon docs --- src/api/notification.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 118330c..8cc3e20 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -270,6 +270,9 @@ impl<'a> Notification { /// Sets the application icon for the notification. /// + /// Refer to the [documentation](https://specifications.freedesktop.org/icon-naming/latest/) for + /// icon names. + /// /// If this function is not called, the application icon will be set from the value set via /// `set_app_icon()`. /// From d50bac9e0e22143796a237da4aec232e25416001 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 14:57:55 +0200 Subject: [PATCH 16/26] docs: add doctest to notification::close --- src/api/notification.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 8cc3e20..dc5b4f3 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -227,6 +227,22 @@ impl<'a> Notification { /// /// # Errors /// This function can return LibnotifyError::{AllocationError, GerrorError} + /// + /// # Example + /// ```no_run(Not notification deamon on CI) + /// use libnotify_rs::api::{functions::init, notification::Notification}; + /// + /// fn main() -> Result<(), Box> { + /// init("Test app")?; + /// let notification = Notification::new("My notification", "Yap yap", None)?; + /// notification.show()?; + /// std::thread::sleep(std::time::Duration::from_secs(5)); // To do this you can just set duration, + /// // but this is an example + /// notification.close()?; // After 5 seconds no notification + /// + /// Ok(()) + /// } + /// ``` pub fn close(&self) -> Result<(), LibnotifyError> { let mut gerror = std::ptr::null_mut() as *mut GError; From c231911f6b2010dc143be58e3ff4796961573b95 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:00:13 +0200 Subject: [PATCH 17/26] docs: add doctest to notification::get_close_reasoin --- src/api/notification.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index dc5b4f3..293f7dc 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -273,6 +273,37 @@ impl<'a> Notification { /// Returns the closed reason code for the notification. /// /// This is valid only after the Notification::closed signal is emitted. + /// + /// This function needs a [glib mainloop](https://docs.gtk.org/glib/main-loop.html) + /// + /// # Example + /// ```no_run(No notificaton daemon on CI) + /// use glib::MainLoop; + /// use libnotify_rs::{ + /// api::functions::{init, uninit}, + /// api::notification::Notification, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("Coffee reminder")?; + /// let mut notify = Notification::new("Drink coffee", "Click me when you're done drinking", None)?; + /// + /// // We need to have a glib main loop in order to receive closed_reason + /// let main_loop = MainLoop::new(None, false); + /// let loop_clone = main_loop.clone(); + /// + /// notify.show()?; + /// main_loop.run(); + /// + /// // Thanks to the main loop we can also read why the notification was closed + /// println!( + /// "Notification closed, because: {:?}", + /// notify.get_closed_reason() + /// ); + /// + /// Ok(()) + /// } + ///``` pub fn get_closed_reason(&self) -> ClosedReason { match unsafe { notify_notification_get_closed_reason(self.inner) } { NotifyClosedReason_NOTIFY_CLOSED_REASON_UNSET => ClosedReason::Unset, From 8172a5f9fbc4228aa7e4dbf431499e110fc707df Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:01:33 +0200 Subject: [PATCH 18/26] docs: add doctest to notification::show --- src/api/notification.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 293f7dc..b0f94ce 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -419,6 +419,27 @@ impl<'a> Notification { /// /// # Errors /// This function can return LibnotifyError::{GerrorError, AllocationError} + /// + /// # Example + /// ```no_run(No notification daemon on CI) + /// use libnotify_rs::api::{ + /// functions::{init, uninit}, + /// notification::{self, Notification}, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("I love coffee")?; + /// let mut notify = Notification::new( + /// "Remember to drink coffe!", + /// "Coffee is very important for your mental health!", + /// None, + /// )?; + /// + /// notify.show()?; + /// + /// Ok(()) + /// } + /// ``` pub fn show(&self) -> Result<(), LibnotifyError> { let mut gerror = std::ptr::null_mut() as *mut GError; From fdbf3326153c2aa17d9187d082c5096d616763e3 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:03:43 +0200 Subject: [PATCH 19/26] docs: add doctest to notification::update --- src/api/notification.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index b0f94ce..37cd24c 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -472,6 +472,19 @@ impl<'a> Notification { /// /// # Errors /// This function can return LibnotifyError::{NulError} + /// + /// # Example + /// ``` + /// use libnotify_rs::api::{functions::init, notification::Notification}; + /// + /// fn main() -> Result<(), Box> { + /// init("Test app")?; + /// let mut notification = Notification::new("My notification", "Yap yap", None)?; + /// notification.update("My new summary", "My new body", None)?; + /// + /// Ok(()) + /// } + /// ``` pub fn update<'b, F, I>( &mut self, summary: &str, From 7b37916381499d0fda827e2ee156cb5f94f6298b Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:05:36 +0200 Subject: [PATCH 20/26] docs: add docs to callback helper functions --- src/api/notification.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index 37cd24c..f3bc057 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -524,6 +524,7 @@ impl Drop for Notification { } } +/// This function translates c callback to rust. Used in `add_action` unsafe extern "C" fn action_trampoline( _notification: *mut NotifyNotification, action: *mut ::std::os::raw::c_char, @@ -541,6 +542,7 @@ unsafe extern "C" fn action_trampoline( callback(&action); } +/// This function tells c how to free memory of our callback unsafe extern "C" fn drop_box(data: gpointer) { unsafe { drop(Box::from_raw(data as *mut F)) }; } From e78c77f12ec971983e47d78a44747092e8ef77b7 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:07:52 +0200 Subject: [PATCH 21/26] docs: add doctest to notification::set_urgency --- src/api/notification.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index f3bc057..a3557e1 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -405,6 +405,25 @@ impl<'a> Notification { } /// Sets the urgency level of this notification + /// # Example + /// ``` + /// use libnotify_rs::api::{ + /// functions::{init, uninit}, + /// notification::{self, Notification}, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("I love coffee")?; + /// let mut notify = Notification::new( + /// "Remember to drink coffe!", + /// "Coffee is very important for your mental health!", + /// None, + /// )?; + /// + /// notify.set_urgency(notification::Urgency::Critical); // coffee is very important + /// Ok(()) + /// } + /// ``` pub fn set_urgency(&mut self, urgency: Urgency) { let urgency: u32 = match urgency { Urgency::Low => NotifyUrgency_NOTIFY_URGENCY_LOW, @@ -578,4 +597,7 @@ mod tests { .is_null() ); } + + // I meant to write more tests, but I'm to lazy :3 + // Doctests should suffice } From 7aa48def4c365188af3f755a76425756be0c44f3 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:08:47 +0200 Subject: [PATCH 22/26] docs: add doctest to notification::set_timeout --- src/api/notification.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/api/notification.rs b/src/api/notification.rs index a3557e1..d014058 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -394,6 +394,26 @@ impl<'a> Notification { /// Sets the timeout of the notification. /// /// Note that the timeout may be ignored by the server. + /// + /// # Example + /// ``` + /// use libnotify_rs::api::{ + /// functions::{init, uninit}, + /// notification::{self, Notification}, + /// }; + /// + /// fn main() -> Result<(), Box> { + /// init("I love coffee")?; + /// let mut notify = Notification::new( + /// "Remember to drink coffe!", + /// "Coffee is very important for your mental health!", + /// None, + /// )?; + /// + /// notify.set_timeout(notification::Timeout::Custom(1000 * 10)); // 10 secs + /// Ok(()) + /// } + /// ``` pub fn set_timeout(&mut self, timeout: Timeout) { let timeout_c = match timeout { Timeout::Default => NOTIFY_EXPIRES_DEFAULT, From f76226242d921400d29e5402cc42ec7fe025dd35 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:13:04 +0200 Subject: [PATCH 23/26] docs: write reference for hint and category down --- src/api/notification.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/notification.rs b/src/api/notification.rs index d014058..4bdaa86 100644 --- a/src/api/notification.rs +++ b/src/api/notification.rs @@ -321,7 +321,7 @@ impl<'a> Notification { /// icon names. /// /// If this function is not called, the application icon will be set from the value set via - /// `set_app_icon()`. + /// `set_app_icon()`. Usage is the same. /// /// Available since: 0.8.4 /// @@ -336,7 +336,7 @@ impl<'a> Notification { /// Sets the application name for the notification. /// - /// If this function is not called, the application name will be set from the value used in init() or overridden with set_app_name(). + /// If this function is not called, the application name will be set from the value used in init() or overridden with set_app_name(). Usage is the same. /// /// Available since: 0.7.3 /// @@ -353,6 +353,8 @@ impl<'a> Notification { /// /// This can be used by the notification server to filter or display the data in a certain way /// + /// The only reference to what this even is, is [this thread](https://unix.stackexchange.com/questions/251243/what-do-a-notify-send-notification-category-hint-and-version-parameters-mean). If you know how to use this bad boy, have fun :D + /// /// # Errors /// This function can return LibnotifyError::{NulError} pub fn set_category(&mut self, category: &str) -> Result<(), LibnotifyError> { @@ -366,6 +368,9 @@ impl<'a> Notification { /// /// Available since: 0.6 /// + /// + /// The only reference to what this even is, is [this thread](https://unix.stackexchange.com/questions/251243/what-do-a-notify-send-notification-category-hint-and-version-parameters-mean). If you know how to use this bad boy, have fun :D + /// /// # Errors /// This function can return LibnotifyError::{NulError, AllocationError} pub fn set_hint(&mut self, key: &str, value: HintValue) -> Result<(), LibnotifyError> { From 71c1dc7bad8d1b410a31db38b412e77daba567ad Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:27:48 +0200 Subject: [PATCH 24/26] docs: add doctests to builder --- src/wrappers/builder.rs | 155 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) 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(()) From 4c2acefdfbfe588937a2660f49462d80a6cc2bb0 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:29:03 +0200 Subject: [PATCH 25/26] docs: add doctests to context --- src/wrappers/context.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wrappers/context.rs b/src/wrappers/context.rs index 12c1c65..ec15815 100644 --- a/src/wrappers/context.rs +++ b/src/wrappers/context.rs @@ -15,6 +15,19 @@ impl LibnotifyContext { /// # Error /// Returns an error, if libnotify cannot be initialized or if there already exists a context /// object + /// + /// # Example + /// ``` + /// use libnotify_rs::context::LibnotifyContext; + /// + /// fn main() -> Result<(), Box> { + /// let ctx = LibnotifyContext::new("Coffee addicted reminder")?; + /// + /// // you don't need to uninitialize libnotify, cause context already does that! + /// + /// Ok(()) + /// } + /// ``` pub fn new(app_name: &str) -> Result> { if IS_CONTEXT_CREATED.swap(true, std::sync::atomic::Ordering::SeqCst) { return Err("You can create only one context at a time".into()); From df49d4d079b22b8c0235bac4b6f00760c42a9593 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 4 Oct 2026 15:34:06 +0200 Subject: [PATCH 26/26] fix: add missing errors section in context docs --- src/wrappers/context.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wrappers/context.rs b/src/wrappers/context.rs index ec15815..ea42d39 100644 --- a/src/wrappers/context.rs +++ b/src/wrappers/context.rs @@ -12,7 +12,7 @@ static IS_CONTEXT_CREATED: std::sync::atomic::AtomicBool = impl LibnotifyContext { /// Try initializing libnotify /// - /// # Error + /// # Errors /// Returns an error, if libnotify cannot be initialized or if there already exists a context /// object /// @@ -41,12 +41,19 @@ impl LibnotifyContext { } /// Sets global app name + /// # Errors + /// + /// This function can return LibnotifyError::NulError pub fn set_new_name(&self, app_name: &str) -> Result<(), LibnotifyError> { set_app_name(app_name)?; Ok(()) } /// Sets global app icon + /// + /// # Errors + /// + /// This function can return LibnotifyError::NulError pub fn set_app_icon(&self, app_icon: &str) -> Result<(), LibnotifyError> { set_app_icon(app_icon)?; Ok(())