From d939bee7ea701d609d51648ec3986cc59d88c8e9 Mon Sep 17 00:00:00 2001 From: "Ospald, Julian" Date: Tue, 11 Jul 2017 15:24:10 +0200 Subject: [PATCH] Cargo fmt --- src/enums.rs | 3 +- src/functions.rs | 32 ++++++++++++++------- src/notification.rs | 70 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 78 insertions(+), 27 deletions(-) diff --git a/src/enums.rs b/src/enums.rs index bcae2fec..a8a0b982 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -27,7 +27,7 @@ impl ToGlib for Urgency { Urgency::Low => ffi::NOTIFY_URGENCY_LOW, Urgency::Normal => ffi::NOTIFY_URGENCY_NORMAL, Urgency::Critical => ffi::NOTIFY_URGENCY_CRITICAL, - Urgency::__Unknown(value) => unsafe{std::mem::transmute(value)} + Urgency::__Unknown(value) => unsafe { std::mem::transmute(value) }, } } } @@ -43,4 +43,3 @@ impl FromGlib for Urgency { } } } - diff --git a/src/functions.rs b/src/functions.rs index 3afab1ba..4d48c144 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -11,9 +11,7 @@ use std::ptr; /// /// `true` if libnotify is initialized, or `false` otherwise. pub fn is_initted() -> bool { - unsafe { - from_glib(ffi::notify_is_initted()) - } + unsafe { from_glib(ffi::notify_is_initted()) } } /// Initialized libnotify. This must be called before any other functions. @@ -23,7 +21,10 @@ pub fn is_initted() -> bool { /// `Ok(())` if successful, `Err(err)` on error. pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> { unsafe { - glib::error::BoolError::from_glib(ffi::notify_init(app_name.to_glib_none().0), "Failed to initialize libnotify") + glib::error::BoolError::from_glib( + ffi::notify_init(app_name.to_glib_none().0), + "Failed to initialize libnotify", + ) } } @@ -34,9 +35,7 @@ pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> { /// The registered application name, passed to `init()`. pub fn get_app_name() -> Option { assert_initialized_libnotify!(); - unsafe { - from_glib_none(ffi::notify_get_app_name()) - } + unsafe { from_glib_none(ffi::notify_get_app_name()) } } /// Synchronously queries the server for its capabilities and returns them as @@ -67,8 +66,22 @@ pub fn get_server_info() -> Option<(String, String, String, String)> { let mut ret_vendor = ptr::null_mut(); let mut ret_version = ptr::null_mut(); let mut ret_spec_version = ptr::null_mut(); - let ret = from_glib(ffi::notify_get_server_info(&mut ret_name, &mut ret_vendor, &mut ret_version, &mut ret_spec_version)); - if ret { Some((from_glib_full(ret_name), from_glib_full(ret_vendor), from_glib_full(ret_version), from_glib_full(ret_spec_version))) } else { None } + let ret = from_glib(ffi::notify_get_server_info( + &mut ret_name, + &mut ret_vendor, + &mut ret_version, + &mut ret_spec_version, + )); + if ret { + Some(( + from_glib_full(ret_name), + from_glib_full(ret_vendor), + from_glib_full(ret_version), + from_glib_full(ret_spec_version), + )) + } else { + None + } } } @@ -92,4 +105,3 @@ pub fn uninit() { ffi::notify_uninit(); } } - diff --git a/src/notification.rs b/src/notification.rs index e28afdf2..eeafbf88 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -36,14 +36,22 @@ impl Notification { /// # Returns /// /// The new `Notification`. - pub fn new<'a, 'b, P: Into>, Q: Into>>(summary: &str, body: P, icon: Q) -> Notification { + pub fn new<'a, 'b, P: Into>, Q: Into>>( + summary: &str, + body: P, + icon: Q, + ) -> Notification { assert_initialized_libnotify!(); let body = body.into(); let body = body.to_glib_none(); let icon = icon.into(); let icon = icon.to_glib_none(); unsafe { - from_glib_full(ffi::notify_notification_new(summary.to_glib_none().0, body.0, icon.0)) + from_glib_full(ffi::notify_notification_new( + summary.to_glib_none().0, + body.0, + icon.0, + )) } } @@ -93,9 +101,7 @@ impl Notification { /// ## `key` /// the hint key /// ## `value` - pub fn set_hint(&self, - key: &str, - value: Option) { + pub fn set_hint(&self, key: &str, value: Option) { assert_initialized_libnotify!(); let gvalue: *mut glib_ffi::GVariant = { @@ -106,9 +112,11 @@ impl Notification { }; unsafe { - ffi::notify_notification_set_hint(self.to_glib_none().0, + ffi::notify_notification_set_hint( + self.to_glib_none().0, key.to_glib_none().0, - gvalue) + gvalue, + ) } } @@ -119,8 +127,10 @@ impl Notification { assert_initialized_libnotify!(); unsafe { - ffi::notify_notification_set_image_from_pixbuf(self.to_glib_none().0, - pixbuf.to_glib_none().0); + ffi::notify_notification_set_image_from_pixbuf( + self.to_glib_none().0, + pixbuf.to_glib_none().0, + ); } } @@ -141,7 +151,10 @@ impl Notification { let app_name = app_name.into(); let app_name = app_name.to_glib_none(); unsafe { - ffi::notify_notification_set_app_name(self.to_glib_none().0, app_name.0); + ffi::notify_notification_set_app_name( + self.to_glib_none().0, + app_name.0, + ); } } @@ -151,7 +164,10 @@ impl Notification { /// The category. pub fn set_category(&self, category: &str) { unsafe { - ffi::notify_notification_set_category(self.to_glib_none().0, category.to_glib_none().0); + ffi::notify_notification_set_category( + self.to_glib_none().0, + category.to_glib_none().0, + ); } } @@ -164,7 +180,10 @@ impl Notification { /// The timeout in milliseconds. pub fn set_timeout(&self, timeout: i32) { unsafe { - ffi::notify_notification_set_timeout(self.to_glib_none().0, timeout); + ffi::notify_notification_set_timeout( + self.to_glib_none().0, + timeout, + ); } } @@ -175,7 +194,10 @@ impl Notification { /// The urgency level. pub fn set_urgency(&self, urgency: Urgency) { unsafe { - ffi::notify_notification_set_urgency(self.to_glib_none().0, urgency.to_glib()); + ffi::notify_notification_set_urgency( + self.to_glib_none().0, + urgency.to_glib(), + ); } } @@ -193,13 +215,31 @@ impl Notification { /// /// `true`, unless an invalid parameter was passed. /// `Ok(())` on success, or `Err(err)` if an invalid parameter was passed - pub fn update<'a, 'b, P: Into>, Q: Into>>(&self, summary: &str, body: P, icon: Q) -> Result<(), glib::error::BoolError> { + pub fn update< + 'a, + 'b, + P: Into>, + Q: Into>, + >( + &self, + summary: &str, + body: P, + icon: Q, + ) -> Result<(), glib::error::BoolError> { let body = body.into(); let body = body.to_glib_none(); let icon = icon.into(); let icon = icon.to_glib_none(); unsafe { - glib::error::BoolError::from_glib(ffi::notify_notification_update(self.to_glib_none().0, summary.to_glib_none().0, body.0, icon.0), "Invalid parameter passed") + glib::error::BoolError::from_glib( + ffi::notify_notification_update( + self.to_glib_none().0, + summary.to_glib_none().0, + body.0, + icon.0, + ), + "Invalid parameter passed", + ) } } }