diff options
Diffstat (limited to 'src/database.rs')
| -rw-r--r-- | src/database.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/database.rs b/src/database.rs index 196932c..c431254 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,5 +1,13 @@ +use std::{ + path, + ptr, +}; + use libc; +use error::Result; +use utils::ToCString; + use ffi; // Re-exported under database module for pretty namespacin'. @@ -9,3 +17,16 @@ pub use ffi::NotmuchDatabaseMode as Mode; pub struct Version(libc::c_uint); pub struct Database(*mut ffi::notmuch_database_t); + +impl Database { + pub fn create<P: path::AsPath>(path: &P) -> Result<Database> { + let path = path.as_path().to_cstring().unwrap(); + + let mut db = ptr::null_mut(); + try!(unsafe { + ffi::notmuch_database_create(path.as_ptr(), &mut db) + }.as_result()); + + Ok(Database(db)) + } +} |
