~bsprague/liars

87694f3dc5de883afcd54a110896fb98944d828c — Brandon Sprague 2 months ago c92ccf9 main
First real swings at Rust FFI for notmuch
1 files changed, 27 insertions(+), 0 deletions(-)

M src/notmuch/mod.rs
M src/notmuch/mod.rs => src/notmuch/mod.rs +27 -0
@@ 2,8 2,35 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::ffi::CString;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

pub fn test_things() {
    println!("testing!!");
}

pub struct Database {}

impl Database {
    pub fn open() {
        unsafe {
            let cfg_path = CString::new(
                std::env::var("NOTMUCH_CONFIG").unwrap_or_else(|_| "~/.notmuch-config".to_string()),
            )
            .unwrap();
            let database_path = CString::new("~/.mail").unwrap(); // TODO: Parse this from cfg_path if available
            let profile = CString::new("TODO").unwrap();
            let mut db: *mut notmuch_database_t = std::ptr::null_mut();
            let mut error_message: *mut i8 = std::ptr::null_mut();
            notmuch_database_open_with_config(
                database_path.as_ptr(),
                notmuch_database_mode_t_NOTMUCH_DATABASE_MODE_READ_ONLY,
                cfg_path.as_ptr(),
                profile.as_ptr(),
                &mut db,
                &mut error_message,
            );
        }
    }
}