Format source code with rustfmt
This commit is contained in:
parent
7bc56e4974
commit
3dfc03aebd
53
src/lib.rs
53
src/lib.rs
@ -25,10 +25,7 @@ use std::ffi::CString;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use gtypes::{
|
use gtypes::{TRUE, FALSE};
|
||||||
TRUE,
|
|
||||||
FALSE
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Error that can happen on context creation
|
/// Error that can happen on context creation
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -36,7 +33,7 @@ pub enum ContextCreationError {
|
|||||||
/// Context already exists
|
/// Context already exists
|
||||||
AlreadyExists,
|
AlreadyExists,
|
||||||
InitFailure,
|
InitFailure,
|
||||||
NulError
|
NulError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ContextCreationError {
|
impl fmt::Display for ContextCreationError {
|
||||||
@ -45,7 +42,7 @@ impl fmt::Display for ContextCreationError {
|
|||||||
match *self {
|
match *self {
|
||||||
AlreadyExists => write!(f, "A Libnotify context already exists."),
|
AlreadyExists => write!(f, "A Libnotify context already exists."),
|
||||||
InitFailure => write!(f, "Failed to initialize libnotify."),
|
InitFailure => write!(f, "Failed to initialize libnotify."),
|
||||||
NulError => write!(f, "Argument contains a nul character.")
|
NulError => write!(f, "Argument contains a nul character."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +50,7 @@ impl fmt::Display for ContextCreationError {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NotificationCreationError {
|
pub enum NotificationCreationError {
|
||||||
NulError,
|
NulError,
|
||||||
Unknown
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NotificationCreationError {
|
impl fmt::Display for NotificationCreationError {
|
||||||
@ -61,7 +58,7 @@ impl fmt::Display for NotificationCreationError {
|
|||||||
use NotificationCreationError::*;
|
use NotificationCreationError::*;
|
||||||
match *self {
|
match *self {
|
||||||
NulError => write!(f, "Argument contains a nul character."),
|
NulError => write!(f, "Argument contains a nul character."),
|
||||||
Unknown => write!(f, "Unknown error")
|
Unknown => write!(f, "Unknown error"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +81,7 @@ impl Context {
|
|||||||
}
|
}
|
||||||
let app_name = match CString::new(app_name) {
|
let app_name = match CString::new(app_name) {
|
||||||
Ok(name) => name,
|
Ok(name) => name,
|
||||||
Err(_) => return Err(ContextCreationError::NulError)
|
Err(_) => return Err(ContextCreationError::NulError),
|
||||||
};
|
};
|
||||||
if sys::notify_init(app_name.as_ptr()) == FALSE {
|
if sys::notify_init(app_name.as_ptr()) == FALSE {
|
||||||
return Err(ContextCreationError::InitFailure);
|
return Err(ContextCreationError::InitFailure);
|
||||||
@ -99,45 +96,47 @@ impl Context {
|
|||||||
/// - summary: Required summary text
|
/// - summary: Required summary text
|
||||||
/// - body: Optional body text
|
/// - body: Optional body text
|
||||||
/// - icon: Optional icon theme icon name or filename
|
/// - icon: Optional icon theme icon name or filename
|
||||||
pub fn new_notification(&self, summary: &str,
|
pub fn new_notification(&self,
|
||||||
body: Option<&str>,
|
summary: &str,
|
||||||
icon: Option<&str>)
|
body: Option<&str>,
|
||||||
-> Result<Notification, NotificationCreationError> {
|
icon: Option<&str>)
|
||||||
|
-> Result<Notification, NotificationCreationError> {
|
||||||
let summary = match CString::new(summary) {
|
let summary = match CString::new(summary) {
|
||||||
Ok(cstr) => cstr,
|
Ok(cstr) => cstr,
|
||||||
Err(_) => return Err(NotificationCreationError::NulError)
|
Err(_) => return Err(NotificationCreationError::NulError),
|
||||||
};
|
};
|
||||||
let body = match body {
|
let body = match body {
|
||||||
Some(body) => match CString::new(body) {
|
Some(body) => match CString::new(body) {
|
||||||
Ok(cstr) => Some(cstr),
|
Ok(cstr) => Some(cstr),
|
||||||
Err(_) => return Err(NotificationCreationError::NulError)
|
Err(_) => return Err(NotificationCreationError::NulError),
|
||||||
},
|
},
|
||||||
None => None
|
None => None,
|
||||||
};
|
};
|
||||||
let body_ptr = match body {
|
let body_ptr = match body {
|
||||||
Some(body) => body.as_ptr(),
|
Some(body) => body.as_ptr(),
|
||||||
None => std::ptr::null()
|
None => std::ptr::null(),
|
||||||
};
|
};
|
||||||
let icon = match icon {
|
let icon = match icon {
|
||||||
Some(icon) => match CString::new(icon) {
|
Some(icon) => match CString::new(icon) {
|
||||||
Ok(cstr) => Some(cstr),
|
Ok(cstr) => Some(cstr),
|
||||||
Err(_) => return Err(NotificationCreationError::NulError)
|
Err(_) => return Err(NotificationCreationError::NulError),
|
||||||
},
|
},
|
||||||
None => None
|
None => None,
|
||||||
};
|
};
|
||||||
let icon_ptr = match icon {
|
let icon_ptr = match icon {
|
||||||
Some(icon) => icon.as_ptr(),
|
Some(icon) => icon.as_ptr(),
|
||||||
None => std::ptr::null()
|
None => std::ptr::null(),
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
let n = sys::notify_notification_new(summary.as_ptr(),
|
let n = sys::notify_notification_new(summary.as_ptr(), body_ptr, icon_ptr);
|
||||||
body_ptr,
|
|
||||||
icon_ptr);
|
|
||||||
if n.is_null() {
|
if n.is_null() {
|
||||||
return Err(NotificationCreationError::Unknown);
|
return Err(NotificationCreationError::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Notification{handle: n, _phantom: PhantomData})
|
Ok(Notification {
|
||||||
|
handle: n,
|
||||||
|
_phantom: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +152,7 @@ impl Drop for Context {
|
|||||||
/// A passive pop-up notification
|
/// A passive pop-up notification
|
||||||
pub struct Notification<'a> {
|
pub struct Notification<'a> {
|
||||||
handle: *mut sys::NotifyNotification,
|
handle: *mut sys::NotifyNotification,
|
||||||
_phantom: PhantomData<&'a Context>
|
_phantom: PhantomData<&'a Context>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Notification<'a> {
|
impl<'a> Notification<'a> {
|
||||||
@ -165,9 +164,9 @@ impl<'a> Notification<'a> {
|
|||||||
sys::notify_notification_show(self.handle, &mut err);
|
sys::notify_notification_show(self.handle, &mut err);
|
||||||
if !err.is_null() {
|
if !err.is_null() {
|
||||||
glib::g_error_free(err);
|
glib::g_error_free(err);
|
||||||
return Err(())
|
return Err(());
|
||||||
}
|
}
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user