docs: write super cool documentation

This commit is contained in:
2026-10-02 15:29:17 +02:00
parent 2140751d2f
commit 6be65a249e
7 changed files with 70 additions and 2 deletions

View File

@@ -3,12 +3,15 @@ use crate::{
wrappers::context::LibnotifyContext,
};
/// Higher level abstraction of `Notification`. Allow for builder pattern notification construction.
/// Requires `LibnotifyContext`
pub struct NotificationBuilder<'a> {
notification: Notification,
_context: &'a LibnotifyContext,
}
impl<'a> NotificationBuilder<'a> {
/// Create new NotificationBuilder, with given context.
pub fn new<T, Y>(
summary: &str,
body: T,
@@ -27,20 +30,25 @@ impl<'a> NotificationBuilder<'a> {
})
}
/// Sets app name for this specific notification.
pub fn set_app_name(mut self, app_name: &str) -> Result<Self, std::ffi::NulError> {
self.notification.set_app_name(app_name)?;
Ok(self)
}
/// Sets app icon fot this specific notification.
pub fn set_app_icon(mut self, app_icon: &str) -> Result<Self, std::ffi::NulError> {
self.notification.set_app_icon(app_icon)?;
Ok(self)
}
/// Sets category for this specific notification
pub fn set_category(mut self, category: &str) -> Result<Self, std::ffi::NulError> {
self.notification.set_category(category)?;
Ok(self)
}
/// Set hint for this specific notification
pub fn set_hint(
mut self,
key: &str,
@@ -50,16 +58,19 @@ impl<'a> NotificationBuilder<'a> {
Ok(self)
}
/// Set timeout until close
pub fn set_timeout(mut self, timeout: Timeout) -> Self {
self.notification.set_timeout(timeout);
self
}
/// Set notification urgency level
pub fn set_urgency(mut self, urgency: Urgency) -> Self {
self.notification.set_urgency(urgency);
self
}
/// Add callback
pub fn add_action<F>(
mut self,
action: &str,
@@ -73,11 +84,15 @@ impl<'a> NotificationBuilder<'a> {
Ok(self)
}
/// Show notification
///
/// Uses `&self` borrow, so you can use this object later, after showing.
pub fn show(&self) -> Result<(), Box<dyn std::error::Error>> {
self.notification.show()?;
Ok(())
}
/// Close notification synchronously.
pub fn close(&self) -> Result<(), Box<dyn std::error::Error>> {
self.notification.close()?;
Ok(())