diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2019-11-13 14:56:32 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2019-11-13 14:56:32 +0100 |
| commit | 3f795961db8228da27bb4823fac2f68e57e7276a (patch) | |
| tree | dbf4916ebbd04ea281f4f86d03148c18a4d02339 /src | |
| parent | 422377021f9a15b30d297b6ead7864098d5b2c2d (diff) | |
| download | mail-3f795961db8228da27bb4823fac2f68e57e7276a.tar.gz | |
port tests from notmuch-python-cffi
Diffstat (limited to 'src')
| -rw-r--r-- | src/database.rs | 24 | ||||
| -rw-r--r-- | src/query.rs | 7 | ||||
| -rw-r--r-- | src/tags.rs | 12 |
3 files changed, 37 insertions, 6 deletions
diff --git a/src/database.rs b/src/database.rs index 53ba76b..44ad040 100644 --- a/src/database.rs +++ b/src/database.rs @@ -6,6 +6,7 @@ use std::ptr; use supercow::Supercow; use libc; +use std::cmp::{PartialEq, PartialOrd, Ordering}; use error::{Error, Result}; use ffi; @@ -25,8 +26,6 @@ use utils::ScopedSupercow; // Re-exported under database module for pretty namespacin'. pub use ffi::DatabaseMode; -#[derive(Copy, Clone, Debug)] -pub struct Version(libc::c_uint); #[derive(Clone, Debug)] pub struct Revision { @@ -34,6 +33,21 @@ pub struct Revision { pub uuid: String, } +impl PartialEq for Revision { + fn eq(&self, other: &Revision) -> bool{ + self.uuid == other.uuid && self.revision == other.revision + } +} + +impl PartialOrd for Revision { + fn partial_cmp(&self, other: &Revision) -> Option<Ordering>{ + if self.uuid != other.uuid { + return None; + } + self.revision.partial_cmp(&other.revision) + } +} + #[derive(Debug)] pub struct Database { @@ -79,7 +93,7 @@ impl Database { }) } - pub fn close(&mut self) -> Result<()> { + pub fn close(&self) -> Result<()> { unsafe { ffi::notmuch_database_close(self.ptr) }.as_result()?; Ok(()) @@ -143,8 +157,8 @@ impl Database { ) } - pub fn version(&self) -> Version { - Version(unsafe { ffi::notmuch_database_get_version(self.ptr) }) + pub fn version(&self) -> u32 { + unsafe { ffi::notmuch_database_get_version(self.ptr) } } #[cfg(feature = "v0_21")] diff --git a/src/query.rs b/src/query.rs index 0ea5268..50b56e5 100644 --- a/src/query.rs +++ b/src/query.rs @@ -46,6 +46,13 @@ impl<'d> Query<'d> { <Database as DatabaseExt>::create_query(db, query_string) } + pub fn query_string(self: &Self) -> String { + let qstring = unsafe { + CStr::from_ptr(ffi::notmuch_query_get_query_string(self.ptr)) + }; + qstring.to_str().unwrap().to_string() + } + /// Specify the sorting desired for this query. pub fn set_sort(self: &Self, sort: Sort) { unsafe { ffi::notmuch_query_set_sort(self.ptr, sort.into()) } diff --git a/src/tags.rs b/src/tags.rs index 3fb1613..40a45c8 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -1,3 +1,4 @@ +use std::cmp::PartialEq; use std::ffi::CStr; use std::iter::Iterator; use std::ops::Drop; @@ -11,7 +12,7 @@ pub trait TagsOwner {} pub struct Tags<'o, O> where O: TagsOwner + 'o, { - ptr: *mut ffi::notmuch_tags_t, + pub(crate) ptr: *mut ffi::notmuch_tags_t, marker: ScopedPhantomcow<'o, O>, } @@ -24,6 +25,15 @@ where } } +impl<'o, O> PartialEq for Tags<'o, O> +where + O: TagsOwner + 'o, +{ + fn eq(&self, other: &Self) -> bool { + self.ptr == other.ptr + } +} + impl<'o, O> Tags<'o, O> where O: TagsOwner + 'o, |
