mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
feat: add specific error docs
This commit is contained in:
@@ -12,6 +12,9 @@ use super::libnotify::*;
|
|||||||
/// Initialized libnotify. This must be called before any other functions.
|
/// Initialized 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.
|
/// 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.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{InitError, NulError}
|
||||||
pub fn init<'a, T>(app_name: T) -> Result<(), LibnotifyError>
|
pub fn init<'a, T>(app_name: T) -> Result<(), LibnotifyError>
|
||||||
where
|
where
|
||||||
T: Into<Option<&'a str>>,
|
T: Into<Option<&'a str>>,
|
||||||
@@ -163,6 +166,9 @@ pub fn get_server_info() -> Option<ServerInfo> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/// Sets the application name
|
/// Sets the application name
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::NulError
|
||||||
pub fn set_app_name(app_name: &str) -> Result<(), LibnotifyError> {
|
pub fn set_app_name(app_name: &str) -> Result<(), LibnotifyError> {
|
||||||
let app_name_c = std::ffi::CString::new(app_name)?;
|
let app_name_c = std::ffi::CString::new(app_name)?;
|
||||||
unsafe { notify_set_app_name(app_name_c.as_ptr()) };
|
unsafe { notify_set_app_name(app_name_c.as_ptr()) };
|
||||||
@@ -174,6 +180,9 @@ pub fn set_app_name(app_name: &str) -> Result<(), LibnotifyError> {
|
|||||||
/// Available since: 0.8.4
|
/// Available since: 0.8.4
|
||||||
///
|
///
|
||||||
/// app_icon is icon name or path to an image
|
/// app_icon is icon name or path to an image
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::NulError
|
||||||
pub fn set_app_icon(app_icon: &str) -> Result<(), LibnotifyError> {
|
pub fn set_app_icon(app_icon: &str) -> Result<(), LibnotifyError> {
|
||||||
let app_icon_c = std::ffi::CString::new(app_icon)?;
|
let app_icon_c = std::ffi::CString::new(app_icon)?;
|
||||||
unsafe { notify_set_app_icon(app_icon_c.as_ptr()) };
|
unsafe { notify_set_app_icon(app_icon_c.as_ptr()) };
|
||||||
|
|||||||
@@ -65,11 +65,7 @@ impl<'a> Notification {
|
|||||||
/// Create new notification.
|
/// Create new notification.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// This function will return an error if the supplied bytes contain an
|
/// This function can return LibnotifyError::{NewNotificationError, NulError}
|
||||||
/// internal 0 byte. The [`NulError`](https://doc.rust-lang.org/stable/alloc/ffi/c_str/struct.NulError.html) returned will contain the bytes as well as
|
|
||||||
/// the position of the nul byte.
|
|
||||||
///
|
|
||||||
/// On libnotify fail it will return Err(&str.into). May change in the future.
|
|
||||||
pub fn new<T, Y>(summary: &str, body: T, icon: Y) -> Result<Self, LibnotifyError>
|
pub fn new<T, Y>(summary: &str, body: T, icon: Y) -> Result<Self, LibnotifyError>
|
||||||
where
|
where
|
||||||
T: Into<Option<&'a str>>,
|
T: Into<Option<&'a str>>,
|
||||||
@@ -105,6 +101,9 @@ impl<'a> Notification {
|
|||||||
/// `label` – label for user
|
/// `label` – label for user
|
||||||
///
|
///
|
||||||
/// `callback` - any closure that accepts &str as an argument, where &str is action name.
|
/// `callback` - any closure that accepts &str as an argument, where &str is action name.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::NulError
|
||||||
pub fn add_action<F>(
|
pub fn add_action<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
action: &str,
|
action: &str,
|
||||||
@@ -147,6 +146,9 @@ impl<'a> Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Synchronously tells the notification server to hide the notification on the screen
|
/// Synchronously tells the notification server to hide the notification on the screen
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{AllocationError, GerrorError}
|
||||||
pub fn close(&self) -> Result<(), LibnotifyError> {
|
pub fn close(&self) -> Result<(), LibnotifyError> {
|
||||||
let mut gerror = std::ptr::null_mut() as *mut GError;
|
let mut gerror = std::ptr::null_mut() as *mut GError;
|
||||||
|
|
||||||
@@ -194,6 +196,9 @@ impl<'a> Notification {
|
|||||||
/// `set_app_icon()`.
|
/// `set_app_icon()`.
|
||||||
///
|
///
|
||||||
/// Available since: 0.8.4
|
/// Available since: 0.8.4
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_app_icon(&mut self, app_icon: &str) -> Result<(), LibnotifyError> {
|
pub fn set_app_icon(&mut self, app_icon: &str) -> Result<(), LibnotifyError> {
|
||||||
let app_icon_c = std::ffi::CString::new(app_icon)?;
|
let app_icon_c = std::ffi::CString::new(app_icon)?;
|
||||||
unsafe { notify_notification_set_app_icon(self.inner, app_icon_c.as_ptr()) };
|
unsafe { notify_notification_set_app_icon(self.inner, app_icon_c.as_ptr()) };
|
||||||
@@ -206,6 +211,9 @@ impl<'a> 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().
|
||||||
///
|
///
|
||||||
/// Available since: 0.7.3
|
/// Available since: 0.7.3
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_app_name(&mut self, app_name: &str) -> Result<(), LibnotifyError> {
|
pub fn set_app_name(&mut self, app_name: &str) -> Result<(), LibnotifyError> {
|
||||||
let app_name_c = std::ffi::CString::new(app_name)?;
|
let app_name_c = std::ffi::CString::new(app_name)?;
|
||||||
unsafe { notify_notification_set_app_name(self.inner, app_name_c.as_ptr()) };
|
unsafe { notify_notification_set_app_name(self.inner, app_name_c.as_ptr()) };
|
||||||
@@ -216,6 +224,9 @@ impl<'a> Notification {
|
|||||||
/// Sets the category of this notification.
|
/// Sets the category of this notification.
|
||||||
///
|
///
|
||||||
/// This can be used by the notification server to filter or display the data in a certain way
|
/// This can be used by the notification server to filter or display the data in a certain way
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_category(&mut self, category: &str) -> Result<(), LibnotifyError> {
|
pub fn set_category(&mut self, category: &str) -> Result<(), LibnotifyError> {
|
||||||
let category_c = std::ffi::CString::new(category)?;
|
let category_c = std::ffi::CString::new(category)?;
|
||||||
unsafe { notify_notification_set_category(self.inner, category_c.as_ptr()) };
|
unsafe { notify_notification_set_category(self.inner, category_c.as_ptr()) };
|
||||||
@@ -226,6 +237,9 @@ impl<'a> Notification {
|
|||||||
/// Sets a hint for key with value value
|
/// Sets a hint for key with value value
|
||||||
///
|
///
|
||||||
/// Available since: 0.6
|
/// Available since: 0.6
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError, AllocationError}
|
||||||
pub fn set_hint(&mut self, key: &str, value: HintValue) -> Result<(), LibnotifyError> {
|
pub fn set_hint(&mut self, key: &str, value: HintValue) -> Result<(), LibnotifyError> {
|
||||||
let key_c = std::ffi::CString::new(key)?;
|
let key_c = std::ffi::CString::new(key)?;
|
||||||
|
|
||||||
@@ -274,6 +288,9 @@ impl<'a> Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tells the notification server to display the notification on the screen
|
/// Tells the notification server to display the notification on the screen
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{GerrorError, AllocationError}
|
||||||
pub fn show(&self) -> Result<(), LibnotifyError> {
|
pub fn show(&self) -> Result<(), LibnotifyError> {
|
||||||
let mut gerror = std::ptr::null_mut() as *mut GError;
|
let mut gerror = std::ptr::null_mut() as *mut GError;
|
||||||
|
|
||||||
@@ -303,12 +320,15 @@ impl<'a> Notification {
|
|||||||
/// Updates the notification text and icon.
|
/// Updates the notification text and icon.
|
||||||
///
|
///
|
||||||
/// This won’t send the update out and display it on the screen. For that, you will need to call `show()`.
|
/// This won’t send the update out and display it on the screen. For that, you will need to call `show()`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn update<'b, F, I>(
|
pub fn update<'b, F, I>(
|
||||||
&mut self,
|
&mut self,
|
||||||
summary: &str,
|
summary: &str,
|
||||||
body: F,
|
body: F,
|
||||||
icon: I,
|
icon: I,
|
||||||
) -> Result<(), std::ffi::NulError>
|
) -> Result<(), LibnotifyError>
|
||||||
where
|
where
|
||||||
F: Into<Option<&'b str>>,
|
F: Into<Option<&'b str>>,
|
||||||
I: Into<Option<&'b str>>,
|
I: Into<Option<&'b str>>,
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ pub struct NotificationBuilder<'a> {
|
|||||||
|
|
||||||
impl<'a> NotificationBuilder<'a> {
|
impl<'a> NotificationBuilder<'a> {
|
||||||
/// Create new NotificationBuilder, with given context.
|
/// Create new NotificationBuilder, with given context.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function can return LibnotifyError::{NewNotificationError, NulError}
|
||||||
pub fn new<T, Y>(
|
pub fn new<T, Y>(
|
||||||
summary: &str,
|
summary: &str,
|
||||||
body: T,
|
body: T,
|
||||||
@@ -34,6 +38,9 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets app name for this specific notification.
|
/// Sets app name for this specific notification.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_app_name<T: Into<Option<&'a str>>>(
|
pub fn set_app_name<T: Into<Option<&'a str>>>(
|
||||||
mut self,
|
mut self,
|
||||||
app_name: T,
|
app_name: T,
|
||||||
@@ -46,6 +53,9 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets app icon fot this specific notification.
|
/// Sets app icon fot this specific notification.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_app_icon<T: Into<Option<&'a str>>>(
|
pub fn set_app_icon<T: Into<Option<&'a str>>>(
|
||||||
mut self,
|
mut self,
|
||||||
app_icon: T,
|
app_icon: T,
|
||||||
@@ -58,6 +68,9 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets category for this specific notification
|
/// Sets category for this specific notification
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError}
|
||||||
pub fn set_category<T: Into<Option<&'a str>>>(
|
pub fn set_category<T: Into<Option<&'a str>>>(
|
||||||
mut self,
|
mut self,
|
||||||
category: T,
|
category: T,
|
||||||
@@ -70,6 +83,8 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set hint for this specific notification
|
/// Set hint for this specific notification
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{NulError, AllocationError}
|
||||||
pub fn set_hint(mut self, key: &str, value: HintValue) -> Result<Self, LibnotifyError> {
|
pub fn set_hint(mut self, key: &str, value: HintValue) -> Result<Self, LibnotifyError> {
|
||||||
self.notification.set_hint(key, value)?;
|
self.notification.set_hint(key, value)?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
@@ -94,12 +109,15 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add callback
|
/// Add callback
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::NulError
|
||||||
pub fn add_action<F>(
|
pub fn add_action<F>(
|
||||||
mut self,
|
mut self,
|
||||||
action: &str,
|
action: &str,
|
||||||
label: &str,
|
label: &str,
|
||||||
callback: F,
|
callback: F,
|
||||||
) -> Result<Self, Box<dyn std::error::Error>>
|
) -> Result<Self, LibnotifyError>
|
||||||
where
|
where
|
||||||
F: Fn(&str) + 'static,
|
F: Fn(&str) + 'static,
|
||||||
{
|
{
|
||||||
@@ -110,13 +128,21 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
/// Show notification
|
/// Show notification
|
||||||
///
|
///
|
||||||
/// Uses `&self` borrow, so you can use this object later, after showing.
|
/// Uses `&self` borrow, so you can use this object later, after showing.
|
||||||
pub fn show(&self) -> Result<(), Box<dyn std::error::Error>> {
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{GerrorError, AllocationError}
|
||||||
|
pub fn show(&self) -> Result<(), LibnotifyError> {
|
||||||
self.notification.show()?;
|
self.notification.show()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close notification synchronously.
|
/// Close notification synchronously.
|
||||||
pub fn close(&self) -> Result<(), Box<dyn std::error::Error>> {
|
///
|
||||||
|
/// Uses `&self` borrow, so you can use this object later, after closing.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// This function can return LibnotifyError::{GerrorError, AllocationError}
|
||||||
|
pub fn close(&self) -> Result<(), LibnotifyError> {
|
||||||
self.notification.close()?;
|
self.notification.close()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user