aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs2
-rw-r--r--src/utils.rs12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f7358b7..379be2f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-#![feature(core, libc)]
+#![feature(core, libc, std_misc)]
extern crate libc;
#[macro_use]
diff --git a/src/utils.rs b/src/utils.rs
index ad8bcac..7e17ab9 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -3,6 +3,8 @@ use std::{
str,
};
+use std::os::unix::ffi::OsStrExt;
+
use libc;
pub trait NotmuchEnum {
@@ -12,6 +14,16 @@ pub trait NotmuchEnum {
fn to_notmuch_t(self) -> Self::NotmuchT;
}
+pub trait ToCString {
+ fn to_cstring(&self) -> Result<ffi::CString, ffi::NulError>;
+}
+
+impl<T: ffi::AsOsStr> ToCString for T {
+ fn to_cstring(&self) -> Result<ffi::CString, ffi::NulError> {
+ self.as_os_str().to_cstring()
+ }
+}
+
pub trait ToStr {
fn to_str(&self) -> Result<&str, str::Utf8Error>;
}