Cargo fmt

This commit is contained in:
Ospald, Julian 2017-07-11 15:24:10 +02:00
parent 557ebbc93f
commit d939bee7ea
3 changed files with 78 additions and 27 deletions

View File

@ -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<ffi::NotifyUrgency> for Urgency {
}
}
}

View File

@ -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<String> {
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();
}
}

View File

@ -36,14 +36,22 @@ impl Notification {
/// # Returns
///
/// The new `Notification`.
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(summary: &str, body: P, icon: Q) -> Notification {
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(
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<glib::variant::Variant>) {
pub fn set_hint(&self, key: &str, value: Option<glib::variant::Variant>) {
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<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, summary: &str, body: P, icon: Q) -> Result<(), glib::error::BoolError> {
pub fn update<
'a,
'b,
P: Into<Option<&'a str>>,
Q: Into<Option<&'b str>>,
>(
&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",
)
}
}
}