docs: add doctests to context

This commit is contained in:
2026-10-04 15:29:03 +02:00
parent 71c1dc7bad
commit 4c2acefdfb

View File

@@ -15,6 +15,19 @@ impl LibnotifyContext {
/// # Error /// # Error
/// Returns an error, if libnotify cannot be initialized or if there already exists a context /// Returns an error, if libnotify cannot be initialized or if there already exists a context
/// object /// object
///
/// # Example
/// ```
/// use libnotify_rs::context::LibnotifyContext;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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<LibnotifyContext, Box<dyn std::error::Error>> { pub fn new(app_name: &str) -> Result<LibnotifyContext, Box<dyn std::error::Error>> {
if IS_CONTEXT_CREATED.swap(true, std::sync::atomic::Ordering::SeqCst) { if IS_CONTEXT_CREATED.swap(true, std::sync::atomic::Ordering::SeqCst) {
return Err("You can create only one context at a time".into()); return Err("You can create only one context at a time".into());