aboutsummaryrefslogtreecommitdiffstats
path: root/notmuch/src/index.rs
blob: 4db6bc79f2316d4bd2c94fdb86bd42b9b9c80be0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::ops::Drop;

use error::Result;
use ffi;
use ffi::DecryptionPolicy;
use Database;
use utils::ScopedPhantomcow;


#[derive(Debug)]
pub struct IndexOpts<'d> {
    pub(crate) ptr: *mut ffi::notmuch_indexopts_t,
    marker: ScopedPhantomcow<'d, Database>,
}

impl<'d> Drop for IndexOpts<'d> {
    fn drop(&mut self) {
        unsafe { ffi::notmuch_indexopts_destroy(self.ptr) };
    }
}

impl<'d> IndexOpts<'d> {
    pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_indexopts_t, owner: O) -> IndexOpts<'d>
    where
        O: Into<ScopedPhantomcow<'d, Database>>,
    {
        IndexOpts {
            ptr,
            marker: owner.into(),
        }
    }

    pub fn set_decrypt_policy(self: &Self, decrypt_policy: DecryptionPolicy) -> Result<()> {
        unsafe { ffi::notmuch_indexopts_set_decrypt_policy(self.ptr, decrypt_policy.into()) }.as_result()
    }

    pub fn decrypt_policy(self: &Self) -> DecryptionPolicy {
        unsafe { ffi::notmuch_indexopts_get_decrypt_policy(self.ptr)}.into()
    }
}

unsafe impl<'d> Send for IndexOpts<'d> {}
unsafe impl<'d> Sync for IndexOpts<'d> {}