7 Commits

Author SHA1 Message Date
Mika Attila
d23eabffea Version bump 2015-09-19 09:42:31 +02:00
Mika Attila
ffd99b67e2 Depend on gtypes 2015-09-19 09:42:17 +02:00
Mika Attila
72df2c0adb Version bump 2015-03-27 08:34:00 +01:00
Mika Attila
dac1075025 Update to new crate naming rules 2015-03-25 19:04:43 +01:00
Mika Attila
d3ad5323fb Update doc example 2015-03-10 19:18:44 +01:00
Mika Attila
445f0b6d13 Implement std::fmt::Display for the error types 2015-03-10 19:14:18 +01:00
Mika Attila
a0955acabd Add example to the documentation 2015-03-10 08:46:54 +01:00
3 changed files with 54 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
[package]
name = "libnotify"
version = "0.0.2"
version = "0.0.4"
authors = ["Mika Attila <radiantstatue@gmail.com>"]
license = "MIT"
description = "Rust bindings to libnotify"
@@ -13,3 +13,4 @@ keywords = ["libnotify", "notification"]
[dependencies]
libnotify-sys = "*"
glib-2_0-sys = "*"
gtypes = "*"

View File

@@ -1,9 +1,12 @@
extern crate libnotify;
fn main() {
let notify = libnotify::Context::new("hello").unwrap();
let notify = libnotify::Context::new("hello").unwrap_or_else(|e| {
panic!("{}", e);
});
let body_text = Some("This is the optional body text.");
let n = notify.new_notification("This is the summary.",
Some("This is the optional body text."),
None).unwrap();
n.show().unwrap();
body_text,
None).unwrap_or_else(|e| panic!("{}", e));
n.show().ok().expect("Failed to show notification");
}

View File

@@ -1,10 +1,31 @@
extern crate "libnotify-sys" as sys;
extern crate "glib-2_0-sys" as glib;
//! Rustic bindings to [libnotify](https://developer.gnome.org/libnotify/)
//!
//! ```rust
//! extern crate libnotify;
//!
//! fn main() {
//! let notify = libnotify::Context::new("hello").unwrap_or_else(|e| {
//! panic!("{}", e);
//! });
//! let body_text = Some("This is the optional body text.");
//! let n = notify.new_notification("This is the summary.",
//! body_text,
//! None).unwrap_or_else(|e| {
//! panic!("{}", e);
//! });
//! n.show().ok().expect("Failed to show notification");
//! }
//! ```
extern crate libnotify_sys as sys;
extern crate glib_2_0_sys as glib;
extern crate gtypes;
use std::ffi::CString;
use std::marker::PhantomData;
use std::fmt;
use glib::types::{
use gtypes::{
TRUE,
FALSE
};
@@ -18,12 +39,33 @@ pub enum ContextCreationError {
NulError
}
impl fmt::Display for ContextCreationError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use ContextCreationError::*;
match *self {
AlreadyExists => write!(f, "A Libnotify context already exists."),
InitFailure => write!(f, "Failed to initialize libnotify."),
NulError => write!(f, "Argument contains a nul character.")
}
}
}
#[derive(Debug)]
pub enum NotificationCreationError {
NulError,
Unknown
}
impl fmt::Display for NotificationCreationError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use NotificationCreationError::*;
match *self {
NulError => write!(f, "Argument contains a nul character."),
Unknown => write!(f, "Unknown error")
}
}
}
/// The context which within libnotify operates.
///
/// Only one context can exist at a time.