diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-05 08:46:59 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-05 08:46:59 +0100 |
| commit | 1b65d6fd6dddae3a365459c7ea744cca3942b6d5 (patch) | |
| tree | 6bec0660b58e46bdcb94161b7b924a2975b93bbc | |
| parent | cc92fea48a3c444822c14ccb6cdfd748f065ef27 (diff) | |
| download | mail-1b65d6fd6dddae3a365459c7ea744cca3942b6d5.tar.gz | |
rustfmt
| -rw-r--r-- | src/database.rs | 25 | ||||
| -rw-r--r-- | src/directory.rs | 13 | ||||
| -rw-r--r-- | src/ffi.rs | 436 | ||||
| -rw-r--r-- | src/message.rs | 48 | ||||
| -rw-r--r-- | src/messages.rs | 13 | ||||
| -rw-r--r-- | src/query.rs | 43 | ||||
| -rw-r--r-- | src/tags.rs | 9 | ||||
| -rw-r--r-- | src/thread.rs | 27 | ||||
| -rw-r--r-- | src/threads.rs | 13 | ||||
| -rw-r--r-- | src/utils.rs | 4 | ||||
| -rw-r--r-- | tests/main.rs | 26 |
11 files changed, 280 insertions, 377 deletions
diff --git a/src/database.rs b/src/database.rs index b73c5c2..c5cb917 100644 --- a/src/database.rs +++ b/src/database.rs @@ -9,10 +9,10 @@ use libc; use error::Result; use ffi; +use query::QueryPtr; use utils::ToStr; use Directory; use Query; -use query::QueryPtr; use Tags; use TagsOwner; @@ -40,12 +40,11 @@ impl Drop for DatabasePtr { } impl DatabasePtr { - pub(crate) fn create_query(&self, query_string: &str) -> Result<QueryPtr> { let query_str = CString::new(query_string).unwrap(); let query = unsafe { ffi::notmuch_query_create(self.ptr, query_str.as_ptr()) }; - + Ok(QueryPtr { ptr: query }) } } @@ -88,7 +87,7 @@ impl Database { Ok(()) } - + pub fn compact<P: AsRef<Path>, F: FnMut(&str)>( path: &P, backup_path: Option<&P>, @@ -222,13 +221,16 @@ impl Database { } } -pub trait DatabaseExt{ - fn create_query<'d, D: Into<Supercow<'d, Database>>>(database: D, query_string: &str) -> Result<Query<'d>> { +pub trait DatabaseExt { + fn create_query<'d, D: Into<Supercow<'d, Database>>>( + database: D, + query_string: &str, + ) -> Result<Query<'d>> { let dbref = database.into(); let query_str = CString::new(query_string).unwrap(); let query = unsafe { ffi::notmuch_query_create(dbref.handle.ptr, query_str.as_ptr()) }; - + Ok(Query::from_ptr(query, Supercow::phantom(dbref))) } @@ -240,8 +242,10 @@ pub trait DatabaseExt{ Ok(Tags::from_ptr(tags, Supercow::phantom(dbref))) } - - fn directory<'d, D: Into<Supercow<'d, Database>>, P: AsRef<Path>>(database: D, path: &P) -> Result<Option<Directory<'d>>> { + fn directory<'d, D: Into<Supercow<'d, Database>>, P: AsRef<Path>>( + database: D, + path: &P, + ) -> Result<Option<Directory<'d>>> { let dbref = database.into(); let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); @@ -262,8 +266,7 @@ pub trait DatabaseExt{ } } -impl DatabaseExt for Database{} - +impl DatabaseExt for Database {} unsafe impl Send for Database {} unsafe impl Sync for Database {} diff --git a/src/directory.rs b/src/directory.rs index 0aa5b80..1d14568 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -2,7 +2,7 @@ use std::ffi::{CStr, CString}; use std::ops::Drop; use std::path::Path; use std::ptr; -use supercow::{Supercow, Phantomcow}; +use supercow::{Phantomcow, Supercow}; use error::Result; use ffi; @@ -45,8 +45,10 @@ impl<'d> Directory<'d> { } } -pub trait DirectoryExt<'d>{ - fn child_directories<'s, S: Into<Supercow<'s, Directory<'d>>>>(directory: S) -> Filenames<'s, Directory<'d>> { +pub trait DirectoryExt<'d> { + fn child_directories<'s, S: Into<Supercow<'s, Directory<'d>>>>( + directory: S, + ) -> Filenames<'s, Directory<'d>> { let dir = directory.into(); Filenames::from_ptr( unsafe { ffi::notmuch_directory_get_child_directories(dir.handle.ptr) }, @@ -55,10 +57,7 @@ pub trait DirectoryExt<'d>{ } } -impl<'d> DirectoryExt<'d> for Directory<'d>{ - -} - +impl<'d> DirectoryExt<'d> for Directory<'d> {} unsafe impl<'d> Send for Directory<'d> {} unsafe impl<'d> Sync for Directory<'d> {} @@ -2,26 +2,11 @@ //! Re-presentation of the notmuch C API. -use libc::{ - c_char, - c_double, - c_int, - c_uint, - c_void, - c_ulong, - time_t, -}; - -use std::{ - error, - fmt, - str, -}; - -use utils::{ - ToStr, -}; +use libc::{c_char, c_double, c_int, c_uint, c_ulong, c_void, time_t}; +use std::{error, fmt, str}; + +use utils::ToStr; notmuch_enum! { #[repr(C)] @@ -48,26 +33,28 @@ notmuch_enum! { impl notmuch_status_t { pub fn is_ok(self) -> bool { - match self { + match self { notmuch_status_t::NOTMUCH_STATUS_SUCCESS => true, _ => false, } } pub fn is_err(self) -> bool { - !self.is_ok() + !self.is_ok() } pub fn as_result(self) -> Result<(), Self> { - if self.is_ok() { Ok(()) } else { Err(self) } + if self.is_ok() { + Ok(()) + } else { + Err(self) + } } } impl ToStr for Status { fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> { - unsafe { - notmuch_status_to_string((*self).into()) - }.to_str() + unsafe { notmuch_status_to_string((*self).into()) }.to_str() } } @@ -124,19 +111,30 @@ notmuch_enum! { } } -#[repr(C)] pub struct notmuch_database_t(c_void); -#[repr(C)] pub struct notmuch_query_t(c_void); -#[repr(C)] pub struct notmuch_threads_t(c_void); -#[repr(C)] pub struct notmuch_thread_t(c_void); -#[repr(C)] pub struct notmuch_messages_t(c_void); -#[repr(C)] pub struct notmuch_message_t(c_void); -#[repr(C)] pub struct notmuch_tags_t(c_void); -#[repr(C)] pub struct notmuch_directory_t(c_void); -#[repr(C)] pub struct notmuch_filenames_t(c_void); -#[repr(C)] pub struct notmuch_message_properties_t(c_void); -#[repr(C)] pub struct notmuch_config_list_t(c_void); -#[repr(C)] pub struct notmuch_indexopts_t(c_void); - +#[repr(C)] +pub struct notmuch_database_t(c_void); +#[repr(C)] +pub struct notmuch_query_t(c_void); +#[repr(C)] +pub struct notmuch_threads_t(c_void); +#[repr(C)] +pub struct notmuch_thread_t(c_void); +#[repr(C)] +pub struct notmuch_messages_t(c_void); +#[repr(C)] +pub struct notmuch_message_t(c_void); +#[repr(C)] +pub struct notmuch_tags_t(c_void); +#[repr(C)] +pub struct notmuch_directory_t(c_void); +#[repr(C)] +pub struct notmuch_filenames_t(c_void); +#[repr(C)] +pub struct notmuch_message_properties_t(c_void); +#[repr(C)] +pub struct notmuch_config_list_t(c_void); +#[repr(C)] +pub struct notmuch_indexopts_t(c_void); pub type notmuch_compact_status_cb_t = extern "C" fn(message: *const c_char, closure: *mut c_void); pub type notmuch_database_upgrade_cb_t = extern "C" fn(closure: *mut c_void, progress: c_double); @@ -146,14 +144,12 @@ pub const TRUE: notmuch_bool_t = 1; pub const FALSE: notmuch_bool_t = 0; #[link(name = "notmuch")] -extern { +extern "C" { /// Get a string representation of a `notmuch_status_t` value. /// /// The result is read-only. - pub fn notmuch_status_to_string( - status: notmuch_status_t, - ) -> *const c_char; + pub fn notmuch_status_to_string(status: notmuch_status_t) -> *const c_char; /// Create a new, empty notmuch database located at 'path'. /// @@ -195,10 +191,11 @@ extern { /// Like `notmuch_database_create`, except optionally return an error /// message. This message is allocated by malloc and should be freed by /// the caller. - pub fn notmuch_database_create_verbose(path: *const c_char, - database: *mut *mut notmuch_database_t, - error_message: *mut *const c_char) - -> notmuch_status_t; + pub fn notmuch_database_create_verbose( + path: *const c_char, + database: *mut *mut notmuch_database_t, + error_message: *mut *const c_char, + ) -> notmuch_status_t; /// Open an existing notmuch database located at 'path'. /// @@ -239,11 +236,12 @@ extern { /// Like notmuch_database_open, except optionally return an error /// message. This message is allocated by malloc and should be freed by /// the caller. - pub fn notmuch_database_open_verbose(path: *const c_char, - mode: notmuch_database_mode_t, - database: *mut *mut notmuch_database_t, - error_message: *mut *mut c_char) - -> notmuch_status_t; + pub fn notmuch_database_open_verbose( + path: *const c_char, + mode: notmuch_database_mode_t, + database: *mut *mut notmuch_database_t, + error_message: *mut *mut c_char, + ) -> notmuch_status_t; /// Retrieve last status string for given database. pub fn notmuch_database_status_string(notmuch: *mut notmuch_database_t) -> *const c_char; @@ -274,9 +272,7 @@ extern { /// * `notmuch_status_t::XAPIAN_EXCEPTION`: A Xapian exception occurred; the /// database has been closed but there are no guarantees the /// changes to the database, if any, have been flushed to disk. - pub fn notmuch_database_close( - database: *mut notmuch_database_t, - ) -> notmuch_status_t; + pub fn notmuch_database_close(database: *mut notmuch_database_t) -> notmuch_status_t; /// Compact a notmuch database, backing up the original database to the /// given path. @@ -299,22 +295,16 @@ extern { /// /// Return value as in `notmuch_database_close` if the database was open; /// `notmuch_database_destroy` itself has no failure modes. - pub fn notmuch_database_destroy( - database: *mut notmuch_database_t, - ) -> notmuch_status_t; + pub fn notmuch_database_destroy(database: *mut notmuch_database_t) -> notmuch_status_t; /// Return the database path of the given database. /// /// The return value is a string owned by notmuch so should not be /// modified nor freed by the caller. - pub fn notmuch_database_get_path( - database: *mut notmuch_database_t, - ) -> *const c_char; + pub fn notmuch_database_get_path(database: *mut notmuch_database_t) -> *const c_char; /// Return the database format version of the given database. - pub fn notmuch_database_get_version( - database: *mut notmuch_database_t, - ) -> c_uint; + pub fn notmuch_database_get_version(database: *mut notmuch_database_t) -> c_uint; /// Can the database be upgraded to a newer database version? /// @@ -324,9 +314,7 @@ extern { /// fail with `notmuch_status_t::UPGRADE_REQUIRED`. This always returns /// FALSE for a read-only database because there's no way to upgrade a /// read-only database. - pub fn notmuch_database_needs_upgrade( - database: *mut notmuch_database_t, - ) -> notmuch_bool_t; + pub fn notmuch_database_needs_upgrade(database: *mut notmuch_database_t) -> notmuch_bool_t; /// Upgrade the current database to the latest supported version. /// @@ -343,12 +331,11 @@ extern { /// the range of [0.0 .. 1.0] indicating the progress made so far in /// the upgrade process. The argument 'closure' is passed verbatim to /// any callback invoked. - pub fn notmuch_database_upgrade(database: *mut notmuch_database_t, - progress_notify: Option<extern "C" fn(closure: *mut c_void, - progress: c_double) - >, - closure: *mut c_void) - -> notmuch_status_t; + pub fn notmuch_database_upgrade( + database: *mut notmuch_database_t, + progress_notify: Option<extern "C" fn(closure: *mut c_void, progress: c_double)>, + closure: *mut c_void, + ) -> notmuch_status_t; /// Begin an atomic database operation. /// @@ -367,9 +354,7 @@ extern { /// /// * `notmuch_status_t::XAPIAN_EXCEPTION`: A Xapian exception occurred; /// atomic section not entered. - pub fn notmuch_database_begin_atomic( - notmuch: *mut notmuch_database_t, - ) -> notmuch_status_t; + pub fn notmuch_database_begin_atomic(notmuch: *mut notmuch_database_t) -> notmuch_status_t; /// Indicate the end of an atomic database operation. /// @@ -382,9 +367,7 @@ extern { /// /// * `notmuch_status_t::UNBALANCED_ATOMIC`: The database is not currently in /// an atomic section. - pub fn notmuch_database_end_atomic( - notmuch: *mut notmuch_database_t, - ) -> notmuch_status_t; + pub fn notmuch_database_end_atomic(notmuch: *mut notmuch_database_t) -> notmuch_status_t; /// Return the committed database revision and UUID. /// @@ -398,9 +381,10 @@ extern { /// The UUID is a NUL-terminated opaque string that uniquely identifies /// this database. Two revision numbers are only comparable if they /// have the same database UUID. - pub fn notmuch_database_get_revision(notmuch: *mut notmuch_database_t, - uuid: *mut *const c_char) - -> c_ulong; + pub fn notmuch_database_get_revision( + notmuch: *mut notmuch_database_t, + uuid: *mut *const c_char, + ) -> c_ulong; /// Retrieve a directory object from the database for 'path'. /// @@ -491,12 +475,11 @@ extern { /// /// @since libnotmuch 5.1 (notmuch 0.26) pub fn notmuch_database_index_file( - database: *mut notmuch_database_t, - filename: *const c_char, - indexopts: *mut notmuch_indexopts_t, - message: *mut *mut notmuch_message_t, - ) -> notmuch_status_t; - + database: *mut notmuch_database_t, + filename: *const c_char, + indexopts: *mut notmuch_indexopts_t, + message: *mut *mut notmuch_message_t, + ) -> notmuch_status_t; /// Deprecated alias for notmuch_database_index_file called with /// NULL indexopts. @@ -603,9 +586,7 @@ extern { /// resulting list contains all tags from all messages found in the database. /// /// On error this function returns NULL. - pub fn notmuch_database_get_all_tags( - db: *mut notmuch_database_t, - ) -> *mut notmuch_tags_t; + pub fn notmuch_database_get_all_tags(db: *mut notmuch_database_t) -> *mut notmuch_tags_t; /// Create a new query for 'database'. /// @@ -636,9 +617,7 @@ extern { ) -> *mut notmuch_query_t; /// Return the query_string of this query. See `notmuch_query_create`. - pub fn notmuch_query_get_query_string( - query: *mut notmuch_query_t, - ) -> *const c_char; + pub fn notmuch_query_get_query_string(query: *mut notmuch_query_t) -> *const c_char; /// Return the notmuch database of this query. See `notmuch_query_create`. pub fn notmuch_query_get_database(query: *const notmuch_query_t) -> *mut notmuch_database_t; @@ -674,24 +653,16 @@ extern { ); /// Specify the sorting desired for this query. - pub fn notmuch_query_set_sort( - query: *mut notmuch_query_t, - sort: notmuch_sort_t, - ); + pub fn notmuch_query_set_sort(query: *mut notmuch_query_t, sort: notmuch_sort_t); /// Return the sort specified for this query. See /// `notmuch_query_set_sort`. - pub fn notmuch_query_get_sort( - query: *mut notmuch_query_t, - ) -> notmuch_sort_t; + pub fn notmuch_query_get_sort(query: *mut notmuch_query_t) -> notmuch_sort_t; /// Add a tag that will be excluded from the query results by default. /// This exclusion will be overridden if this tag appears explicitly in /// the query. - pub fn notmuch_query_add_tag_exclude( - query: *mut notmuch_query_t, - tag: *const c_char, - ); + pub fn notmuch_query_add_tag_exclude(query: *mut notmuch_query_t, tag: *const c_char); /// Execute a query for threads, returning a `notmuch_threads_t` object /// which can be used to iterate over the results. The returned threads @@ -732,9 +703,10 @@ extern { /// to call it if the query is about to be destroyed). /// /// @since libnotmuch 4.2 (notmuch 0.20) - pub fn notmuch_query_search_threads(query: *mut notmuch_query_t, - out: *mut *mut notmuch_threads_t) - -> notmuch_status_t; + pub fn notmuch_query_search_threads( + query: *mut notmuch_query_t, + out: *mut *mut notmuch_threads_t, + ) -> notmuch_status_t; /// Execute a query for messages, returning a `notmuch_messages_t` object /// which can be used to iterate over the results. The returned @@ -777,9 +749,10 @@ extern { /// If a Xapian exception occurs this function will return NULL. /// /// @since libnotmuch 5 (notmuch 0.25) - pub fn notmuch_query_search_messages(query: *mut notmuch_query_t, - out: *mut *mut notmuch_messages_t) - -> notmuch_status_t; + pub fn notmuch_query_search_messages( + query: *mut notmuch_query_t, + out: *mut *mut notmuch_messages_t, + ) -> notmuch_status_t; /// Destroy a `notmuch_query_t` along with any associated resources. /// @@ -788,9 +761,7 @@ extern { /// turn any notmuch_thread_t and `notmuch_message_t` objects generated /// from those results, etc.), if such objects haven't already been /// destroyed. - pub fn notmuch_query_destroy( - query: *mut notmuch_query_t, - ); + pub fn notmuch_query_destroy(query: *mut notmuch_query_t); /// Is the given 'threads' iterator pointing at a valid thread. /// @@ -802,9 +773,7 @@ extern { /// /// See the documentation of `notmuch_query_search_threads` for example /// code showing how to iterate over a `notmuch_threads_t` object. - pub fn notmuch_threads_valid( - threads: *mut notmuch_threads_t, - ) -> notmuch_bool_t; + pub fn notmuch_threads_valid(threads: *mut notmuch_threads_t) -> notmuch_bool_t; /// Get the current thread from 'threads' as a `notmuch_thread_t`. /// @@ -816,9 +785,7 @@ extern { /// /// If an out-of-memory situation occurs, this function will return /// NULL. - pub fn notmuch_threads_get( - threads: *mut notmuch_threads_t, - ) -> *mut notmuch_thread_t; + pub fn notmuch_threads_get(threads: *mut notmuch_threads_t) -> *mut notmuch_thread_t; /// Move the 'threads' iterator to the next thread. /// @@ -829,18 +796,14 @@ extern { /// /// See the documentation of `notmuch_query_search_threads` for example /// code showing how to iterate over a `notmuch_threads_t` object. - pub fn notmuch_threads_move_to_next( - threads: *mut notmuch_threads_t, - ); + pub fn notmuch_threads_move_to_next(threads: *mut notmuch_threads_t); /// Destroy a `notmuch_threads_t` object. /// /// It's not strictly necessary to call this function. All memory from /// the `notmuch_threads_t` object will be reclaimed when the /// containing query object is destroyed. - pub fn notmuch_threads_destroy( - threads: *mut notmuch_threads_t, - ); + pub fn notmuch_threads_destroy(threads: *mut notmuch_threads_t); /// Return the number of messages matching a search. /// @@ -857,10 +820,9 @@ extern { /// @since libnotmuch 4.3 (notmuch 0.21) pub fn notmuch_query_count_messages( query: *mut notmuch_query_t, - count: *mut c_uint + count: *mut c_uint, ) -> notmuch_status_t; - /// Return the number of threads matching a search. /// /// This function performs a search and returns the number of unique thread IDs @@ -883,7 +845,7 @@ extern { /// @since libnotmuch 4.3 (notmuch 0.21) pub fn notmuch_query_count_threads( query: *mut notmuch_query_t, - count: *mut c_uint + count: *mut c_uint, ) -> notmuch_status_t; /// Get the thread ID of 'thread'. @@ -892,17 +854,13 @@ extern { /// modified by the caller and will only be valid for as long as the /// thread is valid, (which is until `notmuch_thread_destroy` or until /// the query from which it derived is destroyed). - pub fn notmuch_thread_get_thread_id( - thread: *mut notmuch_thread_t, - ) -> *const c_char; + pub fn notmuch_thread_get_thread_id(thread: *mut notmuch_thread_t) -> *const c_char; /// Get the total number of messages in 'thread'. /// /// This count consists of all messages in the database belonging to /// this thread. Contrast with `notmuch_thread_get_matched_messages`(). - pub fn notmuch_thread_get_total_messages( - thread: *mut notmuch_thread_t, - ) -> c_int; + pub fn notmuch_thread_get_total_messages(thread: *mut notmuch_thread_t) -> c_int; /// Get the total number of files in 'thread'. /// @@ -911,9 +869,7 @@ extern { /// @returns Non-negative integer /// @since libnotmuch 5.0 (notmuch 0.25) /// - pub fn notmuch_thread_get_total_files( - thread: *mut notmuch_thread_t, - ) -> c_int; + pub fn notmuch_thread_get_total_files(thread: *mut notmuch_thread_t) -> c_int; /// Get a `notmuch_messages_t` iterator for the top-level messages in /// 'thread' in oldest-first order. @@ -931,9 +887,7 @@ extern { /// oldest-first order. /// /// The returned list will be destroyed when the thread is destroyed. - pub fn notmuch_thread_get_messages( - thread: *mut notmuch_thread_t, - ) -> *mut notmuch_messages_t; + pub fn notmuch_thread_get_messages(thread: *mut notmuch_thread_t) -> *mut notmuch_messages_t; /// Get the number of messages in 'thread' that matched the search. /// @@ -942,9 +896,7 @@ extern { /// not excluded by any exclude tags passed in with the query (see /// `notmuch_query_add_tag_exclude`). Contrast with /// `notmuch_thread_get_total_messages`() . - pub fn notmuch_thread_get_matched_messages( - thread: *mut notmuch_thread_t, - ) -> c_int; + pub fn notmuch_thread_get_matched_messages(thread: *mut notmuch_thread_t) -> c_int; /// Get the authors of 'thread' as a UTF-8 string. /// @@ -960,9 +912,7 @@ extern { /// modified by the caller and will only be valid for as long as the /// thread is valid, (which is until `notmuch_thread_destroy` or until /// the query from which it derived is destroyed). - pub fn notmuch_thread_get_authors( - thread: *mut notmuch_thread_t, - ) -> *const c_char; + pub fn notmuch_thread_get_authors(thread: *mut notmuch_thread_t) -> *const c_char; /// Get the subject of 'thread' as a UTF-8 string. /// @@ -974,19 +924,13 @@ extern { /// modified by the caller and will only be valid for as long as the /// thread is valid, (which is until `notmuch_thread_destroy` or until /// the query from which it derived is destroyed). - pub fn notmuch_thread_get_subject( - thread: *mut notmuch_thread_t, - ) -> *const c_char; + pub fn notmuch_thread_get_subject(thread: *mut notmuch_thread_t) -> *const c_char; /// Get the date of the oldest message in 'thread' as a time_t value. - pub fn notmuch_thread_get_oldest_date( - thread: *mut notmuch_thread_t, - ) -> time_t; + pub fn notmuch_thread_get_oldest_date(thread: *mut notmuch_thread_t) -> time_t; /// Get the date of the newest message in 'thread' as a time_t value. - pub fn notmuch_thread_get_newest_date( - thread: *mut notmuch_thread_t, - ) -> time_t; + pub fn notmuch_thread_get_newest_date(thread: *mut notmuch_thread_t) -> time_t; /// Get the tags for 'thread', returning a `notmuch_tags_t` object which /// can be used to iterate over all tags. @@ -1025,14 +969,10 @@ extern { /// `notmuch_tags_t` object. (For consistency, we do provide a /// `notmuch_tags_destroy` function, but there's no good reason to call /// it if the message is about to be destroyed). - pub fn notmuch_thread_get_tags( - thread: *mut notmuch_thread_t, - ) -> *mut notmuch_tags_t; + pub fn notmuch_thread_get_tags(thread: *mut notmuch_thread_t) -> *mut notmuch_tags_t; /// Destroy a `notmuch_thread_t` object. - pub fn notmuch_thread_destroy( - thread: *mut notmuch_thread_t, - ); + pub fn notmuch_thread_destroy(thread: *mut notmuch_thread_t); /// Is the given 'messages' iterator pointing at a valid message. /// @@ -1042,9 +982,7 @@ extern { /// /// See the documentation of `notmuch_query_search_messages` for example /// code showing how to iterate over a `notmuch_messages_t` object. - pub fn notmuch_messages_valid( - messages: *mut notmuch_messages_t, - ) -> notmuch_bool_t; + pub fn notmuch_messages_valid(messages: *mut notmuch_messages_t) -> notmuch_bool_t; /// Get the current message from 'messages' as a `notmuch_message_t`. /// @@ -1056,9 +994,7 @@ extern { /// /// If an out-of-memory situation occurs, this function will return /// NULL. - pub fn notmuch_messages_get( - messages: *mut notmuch_messages_t, - ) -> *mut notmuch_message_t; + pub fn notmuch_messages_get(messages: *mut notmuch_messages_t) -> *mut notmuch_message_t; /// Move the 'messages' iterator to the next message. /// @@ -1069,18 +1005,14 @@ extern { /// /// See the documentation of `notmuch_query_search_messages` for example /// code showing how to iterate over a `notmuch_messages_t` object. - pub fn notmuch_messages_move_to_next( - messages: *mut notmuch_messages_t, - ); + pub fn notmuch_messages_move_to_next(messages: *mut notmuch_messages_t); /// Destroy a `notmuch_messages_t` object. /// /// It's not strictly necessary to call this function. All memory from /// the `notmuch_messages_t` object will be reclaimed when the containing /// query object is destroyed. - pub fn notmuch_messages_destroy( - messages: *mut notmuch_messages_t, - ); + pub fn notmuch_messages_destroy(messages: *mut notmuch_messages_t); /// Return a list of tags from all messages. /// @@ -1093,10 +1025,7 @@ extern { /// message list. /// /// The function returns NULL on error. - pub fn notmuch_messages_collect_tags( - messages: *mut notmuch_messages_t, - ) -> *mut notmuch_tags_t; - + pub fn notmuch_messages_collect_tags(messages: *mut notmuch_messages_t) -> *mut notmuch_tags_t; /// Get the message ID of 'message'. /// @@ -1108,9 +1037,7 @@ extern { /// This function will not return NULL since Notmuch ensures that every /// message has a unique message ID, (Notmuch will generate an ID for a /// message if the original file does not contain one). - pub fn notmuch_message_get_message_id( - message: *mut notmuch_message_t, - ) -> *const c_char; + pub fn notmuch_message_get_message_id(message: *mut notmuch_message_t) -> *const c_char; /// Get the thread ID of 'message'. /// @@ -1122,9 +1049,7 @@ extern { /// /// This function will not return NULL since Notmuch ensures that every /// message belongs to a single thread. - pub fn notmuch_message_get_thread_id( - message: *mut notmuch_message_t, - ) -> *const c_char; + pub fn notmuch_message_get_thread_id(message: *mut notmuch_message_t) -> *const c_char; /// Get a `notmuch_messages_t` iterator for all of the replies to /// 'message'. @@ -1142,16 +1067,12 @@ extern { /// If there are no replies to 'message', this function will return /// NULL. (Note that `notmuch_messages_valid` will accept that NULL /// value as legitimate, and simply return FALSE for it.) - pub fn notmuch_message_get_replies( - message: *mut notmuch_message_t, - ) -> *mut notmuch_messages_t; + pub fn notmuch_message_get_replies(message: *mut notmuch_message_t) -> *mut notmuch_messages_t; /// Get the total number of files associated with a message. /// @returns Non-negative integer /// @since libnotmuch 5.0 (notmuch 0.25) - pub fn notmuch_message_count_files( - message: *mut notmuch_message_t, - ) -> c_int; + pub fn notmuch_message_count_files(message: *mut notmuch_message_t) -> c_int; /// Get a filename for the email corresponding to 'message'. /// @@ -1167,9 +1088,7 @@ extern { /// this function will arbitrarily return a single one of those /// filenames. See `notmuch_message_get_filenames` for returning the /// complete list of filenames. - pub fn notmuch_message_get_filename( - message: *mut notmuch_message_t, - ) -> *const c_char; + pub fn notmuch_message_get_filename(message: *mut notmuch_message_t) -> *const c_char; /// Get all filenames for the email corresponding to 'message'. /// @@ -1201,9 +1120,7 @@ extern { /// For the original textual representation of the Date header from the /// message call `notmuch_message_get_header`() with a header value of /// "date". - pub fn notmuch_message_get_date( - message: *mut notmuch_message_t, - ) -> time_t; + pub fn notmuch_message_get_date(message: *mut notmuch_message_t) -> time_t; /// Get the value of the specified header from 'message' as a UTF-8 string. /// @@ -1255,9 +1172,7 @@ extern { /// `notmuch_tags_t` object. (For consistency, we do provide a /// `notmuch_tags_destroy` function, but there's no good reason to call /// it if the message is about to be destroyed). - pub fn notmuch_message_get_tags( - message: *mut notmuch_message_t, - ) -> *mut notmuch_tags_t; + pub fn notmuch_message_get_tags(message: *mut notmuch_message_t) -> *mut notmuch_tags_t; /// Add a tag to the given message. /// @@ -1291,7 +1206,6 @@ extern { tag: *const c_char, ) -> notmuch_status_t; - /// Remove all tags from the given message. /// /// See `notmuch_message_freeze` for an example showing how to safely @@ -1299,10 +1213,7 @@ extern { /// /// `notmuch_status_t::READ_ONLY_DATABASE`: Database was opened in read-only /// mode so message cannot be modified. - pub fn notmuch_message_remove_all_tags( - message: *mut notmuch_message_t, - ) -> notmuch_status_t; - + pub fn notmuch_message_remove_all_tags(message: *mut notmuch_message_t) -> notmuch_status_t; /// Add/remove tags according to maildir flags in the message filename(s). /// @@ -1416,9 +1327,7 @@ extern { /// /// `notmuch_status_t::READ_ONLY_DATABASE`: Database was opened in read-only /// mode so message cannot be modified. - pub fn notmuch_message_freeze( - message: *mut notmuch_message_t, - ) -> notmuch_status_t; + pub fn notmuch_message_freeze(message: *mut notmuch_message_t) -> notmuch_status_t; /// Thaw the current 'message', synchronizing any changes that may have /// occurred while 'message' was frozen into the notmuch database. @@ -1439,9 +1348,7 @@ extern { /// an unfrozen message. That is, there have been an unbalanced /// number of calls to `notmuch_message_freeze` and /// `notmuch_message_thaw`. - pub fn notmuch_message_thaw( - message: *mut notmuch_message_t, - ) -> notmuch_status_t; + pub fn notmuch_message_thaw(message: *mut notmuch_message_t) -> notmuch_status_t; /// Destroy a `notmuch_message_t` object. /// @@ -1450,9 +1357,7 @@ extern { /// over the entire database). Otherwise, it's fine to never call this /// function and there will still be no memory leaks. (The memory from /// the messages get reclaimed when the containing query is destroyed.) - pub fn notmuch_message_destroy( - message: *mut notmuch_message_t, - ); + pub fn notmuch_message_destroy(message: *mut notmuch_message_t); /// Retrieve the value for a single property key /// @@ -1464,10 +1369,11 @@ extern { /// - `notmuch_status_t::NULL_POINTER`: *value* may not be NULL. /// - `notmuch_status_t::SUCCESS`: No error occured. /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_get_property(message: *mut notmuch_message_t, - key: *const c_char, - value: *mut *const c_char) - -> notmuch_status_t; + pub fn notmuch_message_get_property( + message: *mut notmuch_message_t, + key: *const c_char, + value: *mut *const c_char, + ) -> notmuch_status_t; /// Add a (key,value) pair to a message /// @@ -1476,10 +1382,11 @@ extern { /// - `notmuch_status_t::NULL_POINTER`: Neither *key* nor *value* may be NULL. /// - `notmuch_status_t::SUCCESS`: No error occured. /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_add_property(message: *mut notmuch_message_t, - key: *const c_char, - value: *const c_char) - -> notmuch_status_t; + pub fn notmuch_message_add_property( + message: *mut notmuch_message_t, + key: *const c_char, + value: *const c_char, + ) -> notmuch_status_t; /// /// Remove a `(key,value)` pair from a message. @@ -1491,10 +1398,11 @@ extern { /// - `notmuch_status_t::NULL_POINTER`: Neither `key` nor *value* may be NULL. /// - `notmuch_status_t::SUCCESS`: No error occured. /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_remove_property(message: *mut notmuch_message_t, - key: *const c_char, - value: *const c_char) - -> notmuch_status_t; + pub fn notmuch_message_remove_property( + message: *mut notmuch_message_t, + key: *const c_char, + value: *const c_char, + ) -> notmuch_status_t; /// Remove all `(key,value)` pairs from the given message. /// @@ -1507,9 +1415,10 @@ extern { /// - `notmuch_status_t::SUCCESS`: No error occured. /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_remove_all_properties(message: *mut notmuch_message_t, - key: *const c_char) - -> notmuch_status_t; + pub fn notmuch_message_remove_all_properties( + message: *mut notmuch_message_t, + key: *const c_char, + ) -> notmuch_status_t; /// Get the properties for *message*, returning a /// `notmuch_message_properties_t` object which can be used to iterate over @@ -1544,10 +1453,11 @@ extern { /// /// @since libnotmuch 4.4 (notmuch 0.23) /// - pub fn notmuch_message_get_properties(message: *mut notmuch_message_t, - key: *const c_char, - exact: notmuch_bool_t) - -> *mut notmuch_message_properties_t; + pub fn notmuch_message_get_properties( + message: *mut notmuch_message_t, + key: *const c_char, + exact: notmuch_bool_t, + ) -> *mut notmuch_message_properties_t; /// Is the given *properties* iterator pointing at a valid `(key,value)` pair. /// @@ -1560,7 +1470,9 @@ extern { /// showing how to iterate over a `notmuch_message_properties_t` object. /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_properties_valid(properties: *const notmuch_message_properties_t) -> notmuch_bool_t; + pub fn notmuch_message_properties_valid( + properties: *const notmuch_message_properties_t, + ) -> notmuch_bool_t; /// Move the *properties* iterator to the next `(key,value)` pair /// @@ -1580,15 +1492,18 @@ extern { /// /// @since libnotmuch 4.4 (notmuch 0.23) /// - pub fn notmuch_message_properties_key(properties: *mut notmuch_message_properties_t) -> *const c_char; + pub fn notmuch_message_properties_key( + properties: *mut notmuch_message_properties_t, + ) -> *const c_char; /// Return the `value` from the current `(key,value)` pair. /// /// This could be useful if iterating for a prefix. /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_message_properties_value(properties: *const notmuch_message_properties_t) -> *const c_char; - + pub fn notmuch_message_properties_value( + properties: *const notmuch_message_properties_t, + ) -> *const c_char; /// Destroy a `notmuch_message_properties_t` object. /// @@ -1669,9 +1584,10 @@ extern { /// /// * `notmuch_status_t::READ_ONLY_DATABASE`: Database was opened in read-only mode so /// directory mtime cannot be modified. - pub fn notmuch_directory_set_mtime(directory: *mut notmuch_directory_t, - mtime: time_t) - -> notmuch_status_t; + pub fn notmuch_directory_set_mtime( + directory: *mut notmuch_directory_t, + mtime: time_t, + ) -> notmuch_status_t; /// Get the mtime of a directory, (as previously stored with /// `notmuch_directory_set_mtime`). @@ -1685,16 +1601,18 @@ extern { /// /// The returned filenames will be the basename-entries only (not /// complete paths). - pub fn notmuch_directory_get_child_files(directory: *mut notmuch_directory_t) - -> *mut notmuch_filenames_t; + pub fn notmuch_directory_get_child_files( + directory: *mut notmuch_directory_t, + ) -> *mut notmuch_filenames_t; /// Get a `notmuch_filenames_t` iterator listing all the filenames of /// sub-directories in the database within the given directory. /// /// The returned filenames will be the basename-entries only (not /// complete paths). - pub fn notmuch_directory_get_child_directories(directory: *mut notmuch_directory_t) - -> *mut notmuch_filenames_t; + pub fn notmuch_directory_get_child_directories( + directory: *mut notmuch_directory_t, + ) -> *mut notmuch_filenames_t; /// Delete directory document from the database, and destroy the /// `notmuch_directory_t` object. Assumes any child directories and files @@ -1746,14 +1664,14 @@ extern { /// function will do nothing. pub fn notmuch_filenames_destroy(filenames: *mut notmuch_filenames_t); - /// set config 'key' to 'value' /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_database_set_config(db: *mut notmuch_database_t, - key: *const c_char, - value: *const c_char) - -> notmuch_status_t; + pub fn notmuch_database_set_config( + db: *mut notmuch_database_t, + key: *const c_char, + value: *const c_char, + ) -> notmuch_status_t; /// retrieve config item 'key', assign to 'value' /// @@ -1764,24 +1682,25 @@ extern { /// caller. /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_database_get_config(db: *mut notmuch_database_t, - key: *const c_char, - value: *mut *mut c_char) - -> notmuch_status_t; + pub fn notmuch_database_get_config( + db: *mut notmuch_database_t, + key: *const c_char, + value: *mut *mut c_char, + ) -> notmuch_status_t; /// Create an iterator for all config items with keys matching a given prefix /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_database_get_config_list(db: *mut notmuch_database_t, - prefix: *const c_char, - out: *mut *mut notmuch_config_list_t) - -> notmuch_status_t; + pub fn notmuch_database_get_config_list( + db: *mut notmuch_database_t, + prefix: *const c_char, + out: *mut *mut notmuch_config_list_t, + ) -> notmuch_status_t; /// Is 'config_list' iterator valid (i.e. _key, _value, _move_to_next can be called). /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_config_list_valid(config_list: *mut notmuch_config_list_t) - -> notmuch_bool_t; + pub fn notmuch_config_list_valid(config_list: *mut notmuch_config_list_t) -> notmuch_bool_t; /// return key for current config pair /// @@ -1789,8 +1708,7 @@ extern { /// next call to `notmuch_config_list_key` or `notmuch_config_list_destroy`. /// /// @since libnotmuch 4.4 (notmuch 0.23) - pub fn notmuch_config_list_key (config_list: *mut notmuch_config_list_t) - -> *const c_char; + pub fn notmuch_config_list_key(config_list: *mut notmuch_config_list_t) -> *const c_char; /// return 'value' for current config pair /// diff --git a/src/message.rs b/src/message.rs index 4c35544..dbf7cf2 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,7 +1,7 @@ use std::ffi::CString; use std::ops::Drop; use std::path::PathBuf; -use supercow::{Supercow, Phantomcow}; +use supercow::{Phantomcow, Supercow}; use error::{Error, Result}; use ffi; @@ -80,16 +80,12 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } pub fn date(&self) -> i64 { - unsafe { - ffi::notmuch_message_get_date(self.handle.ptr) - } + unsafe { ffi::notmuch_message_get_date(self.handle.ptr) } } pub fn header(&self, name: &str) -> Result<&str> { let name = CString::new(name).unwrap(); - let ret = unsafe { - ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) - }; + let ret = unsafe { ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) }; if ret.is_null() { Err(Error::UnspecifiedError) } else { @@ -103,56 +99,52 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { pub fn add_tag(self: &Self, tag: &str) -> Status { let tag = CString::new(tag).unwrap(); - Status::from(unsafe { - ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) - }) + Status::from(unsafe { ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) }) } pub fn remove_tag(self: &Self, tag: &str) -> Status { let tag = CString::new(tag).unwrap(); - Status::from(unsafe { - ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) - }) + Status::from(unsafe { ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) }) } pub fn remove_all_tags(self: &Self) -> Status { - Status::from(unsafe { - ffi::notmuch_message_remove_all_tags(self.handle.ptr) - }) + Status::from(unsafe { ffi::notmuch_message_remove_all_tags(self.handle.ptr) }) } } - -pub trait MessageExt<'o, Owner: MessageOwner + 'o>{ - - fn tags<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>(message: S) -> Tags<'s, Message<'o, Owner>> { +pub trait MessageExt<'o, Owner: MessageOwner + 'o> { + fn tags<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>( + message: S, + ) -> Tags<'s, Message<'o, Owner>> { let messageref = message.into(); Tags::from_ptr( unsafe { ffi::notmuch_message_get_tags(messageref.handle.ptr) }, - Supercow::phantom(messageref) + Supercow::phantom(messageref), ) } - fn replies<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>(message: S) -> Messages<'s, Message<'o, Owner>> { + fn replies<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>( + message: S, + ) -> Messages<'s, Message<'o, Owner>> { let messageref = message.into(); Messages::from_ptr( unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) }, - Supercow::phantom(messageref) + Supercow::phantom(messageref), ) } - fn filenames<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>(message: S) -> Filenames<'s, Message<'o, Owner>> { + fn filenames<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>( + message: S, + ) -> Filenames<'s, Message<'o, Owner>> { let messageref = message.into(); Filenames::from_ptr( unsafe { ffi::notmuch_message_get_filenames(messageref.handle.ptr) }, - Supercow::phantom(messageref) + Supercow::phantom(messageref), ) } } -impl<'o, Owner: MessageOwner + 'o> MessageExt<'o, Owner> for Message<'o, Owner>{ - -} +impl<'o, Owner: MessageOwner + 'o> MessageExt<'o, Owner> for Message<'o, Owner> {} unsafe impl<'o, Owner: MessageOwner + 'o> Send for Message<'o, Owner> {} unsafe impl<'o, Owner: MessageOwner + 'o> Sync for Message<'o, Owner> {} diff --git a/src/messages.rs b/src/messages.rs index 7a0a48c..8537f90 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -89,17 +89,14 @@ impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIterator<'s, Message<'s, Se } } -pub trait MessagesExt<'o, Owner: MessagesOwner + 'o> { +pub trait MessagesExt<'o, Owner: MessagesOwner + 'o> {} -} - -impl<'o, Owner: MessagesOwner + 'o> MessagesExt<'o, Owner> for Messages<'o, Owner>{ - -} +impl<'o, Owner: MessagesOwner + 'o> MessagesExt<'o, Owner> for Messages<'o, Owner> {} -impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIteratorExt<'s, Message<'s, Self>> for Messages<'o, Owner> +impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIteratorExt<'s, Message<'s, Self>> + for Messages<'o, Owner> { - fn next<S: Into<Supercow<'s, Messages<'o, Owner>>>>(messages: S) -> Option<Message<'s, Self>>{ + fn next<S: Into<Supercow<'s, Messages<'o, Owner>>>>(messages: S) -> Option<Message<'s, Self>> { let messagesref = messages.into(); let valid = unsafe { ffi::notmuch_messages_valid(messagesref.handle.ptr) }; diff --git a/src/query.rs b/src/query.rs index b502542..c3eb1a2 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,19 +1,19 @@ +use std::ffi::{CStr, CString}; use std::ops::Drop; use std::ptr; -use std::ffi::{CStr, CString}; -use supercow::{Supercow, Phantomcow}; +use supercow::{Phantomcow, Supercow}; use error::Result; use ffi; use ffi::Sort; +use messages::MessagesPtr; +use threads::ThreadsPtr; use Database; use Messages; use MessagesOwner; use Threads; use ThreadsOwner; -use threads::ThreadsPtr; -use messages::MessagesPtr; #[derive(Debug)] pub(crate) struct QueryPtr { @@ -36,13 +36,12 @@ impl<'d> ThreadsOwner for Query<'d> {} impl<'d> MessagesOwner for Query<'d> {} impl<'d> Query<'d> { - pub(crate) fn from_ptr<O: Into<Phantomcow<'d, Database>>>( ptr: *mut ffi::notmuch_query_t, owner: O, ) -> Query<'d> { Query { - handle: QueryPtr{ptr}, + handle: QueryPtr { ptr }, marker: owner.into(), } } @@ -57,13 +56,12 @@ impl<'d> Query<'d> { } } - pub fn create<D: Into<Supercow<'d, Database>>>(db: D, - query_string: &str) -> Result<Self> { - + pub fn create<D: Into<Supercow<'d, Database>>>(db: D, query_string: &str) -> Result<Self> { let dbref = db.into(); - dbref.handle.create_query(query_string).map(move |handle|{ - Query::from_handle(handle, Supercow::phantom(dbref)) - }) + dbref + .handle + .create_query(query_string) + .map(move |handle| Query::from_handle(handle, Supercow::phantom(dbref))) } /// Specify the sorting desired for this query. @@ -101,34 +99,37 @@ impl<'d> Query<'d> { } } -pub trait QueryExt<'d>{ - - fn search_threads<'q, Q: Into<Supercow<'q, Query<'d>>>>(query: Q) -> Result<Threads<'q, Query<'d>>>{ +pub trait QueryExt<'d> { + fn search_threads<'q, Q: Into<Supercow<'q, Query<'d>>>>( + query: Q, + ) -> Result<Threads<'q, Query<'d>>> { let queryref = query.into(); let mut thrds = ptr::null_mut(); try!( - unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) }.as_result() + unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) } + .as_result() ); Ok(Threads::from_ptr(thrds, Supercow::phantom(queryref))) } - fn search_messages<'q, Q: Into<Supercow<'q, Query<'d>>>>(query: Q) -> Result<Messages<'q, Query<'d>>>{ + fn search_messages<'q, Q: Into<Supercow<'q, Query<'d>>>>( + query: Q, + ) -> Result<Messages<'q, Query<'d>>> { let queryref = query.into(); let mut msgs = ptr::null_mut(); try!( - unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) }.as_result() + unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) } + .as_result() ); Ok(Messages::from_ptr(msgs, Supercow::phantom(queryref))) } - } -impl<'d> QueryExt<'d> for Query<'d>{} - +impl<'d> QueryExt<'d> for Query<'d> {} unsafe impl<'d> Send for Query<'d> {} unsafe impl<'d> Sync for Query<'d> {} diff --git a/src/tags.rs b/src/tags.rs index dcf205a..573a491 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -58,14 +58,9 @@ impl<'o, Owner: TagsOwner + 'o> Iterator for Tags<'o, Owner> { } } +pub trait TagsExt<'o, Owner: TagsOwner + 'o> {} -pub trait TagsExt<'o, Owner: TagsOwner + 'o>{ - -} - -impl<'o, Owner: TagsOwner + 'o> TagsExt<'o, Owner> for Tags<'o, Owner>{ - -} +impl<'o, Owner: TagsOwner + 'o> TagsExt<'o, Owner> for Tags<'o, Owner> {} unsafe impl<'o, Owner: TagsOwner + 'o> Send for Tags<'o, Owner> {} unsafe impl<'o, Owner: TagsOwner + 'o> Sync for Tags<'o, Owner> {} diff --git a/src/thread.rs b/src/thread.rs index e9ecdad..a529508 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -1,5 +1,5 @@ use std::ops::Drop; -use supercow::{Supercow, Phantomcow}; +use supercow::{Phantomcow, Supercow}; use ffi; use utils::ToStr; @@ -97,38 +97,41 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { } } -pub trait ThreadExt<'o, Owner: ThreadOwner + 'o>{ - fn tags<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Tags<'s, Thread<'o, Owner>> { +pub trait ThreadExt<'o, Owner: ThreadOwner + 'o> { + fn tags<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>( + thread: S, + ) -> Tags<'s, Thread<'o, Owner>> { let threadref = thread.into(); Tags::from_ptr( unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) }, - Supercow::phantom(threadref) + Supercow::phantom(threadref), ) } - fn toplevel_messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Messages<'s, Thread<'o, Owner>> { + fn toplevel_messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>( + thread: S, + ) -> Messages<'s, Thread<'o, Owner>> { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) }, - Supercow::phantom(threadref) + Supercow::phantom(threadref), ) } /// Get a `Messages` iterator for all messages in 'thread' in /// oldest-first order. - fn messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Messages<'s, Thread<'o, Owner>> { + fn messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>( + thread: S, + ) -> Messages<'s, Thread<'o, Owner>> { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) }, - Supercow::phantom(threadref) + Supercow::phantom(threadref), ) } - } -impl<'o, Owner: ThreadOwner + 'o> ThreadExt<'o, Owner> for Thread<'o, Owner>{ - -} +impl<'o, Owner: ThreadOwner + 'o> ThreadExt<'o, Owner> for Thread<'o, Owner> {} unsafe impl<'o, Owner: ThreadOwner + 'o> Send for Thread<'o, Owner> {} unsafe impl<'o, Owner: ThreadOwner + 'o> Sync for Thread<'o, Owner> {} diff --git a/src/threads.rs b/src/threads.rs index 5083f87..e2312c7 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -48,17 +48,14 @@ impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIterator<'s, Thread<'s, Self } } -pub trait ThreadsExt<'o, Owner: ThreadsOwner + 'o>{ +pub trait ThreadsExt<'o, Owner: ThreadsOwner + 'o> {} -} - -impl<'o, Owner: ThreadsOwner + 'o> ThreadsExt<'o, Owner> for Threads<'o, Owner>{ - -} +impl<'o, Owner: ThreadsOwner + 'o> ThreadsExt<'o, Owner> for Threads<'o, Owner> {} -impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIteratorExt<'s, Thread<'s, Self>> for Threads<'o, Owner> +impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIteratorExt<'s, Thread<'s, Self>> + for Threads<'o, Owner> { - fn next<S: Into<Supercow<'s, Threads<'o, Owner>>>>(threads: S) -> Option<Thread<'s, Self>>{ + fn next<S: Into<Supercow<'s, Threads<'o, Owner>>>>(threads: S) -> Option<Thread<'s, Self>> { let threadsref = threads.into(); let valid = unsafe { ffi::notmuch_threads_valid(threadsref.handle.ptr) }; diff --git a/src/utils.rs b/src/utils.rs index def8d93..be5f66c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -34,6 +34,6 @@ pub trait StreamingIteratorExt<'a, T> { /// Return either the next item in the sequence, or `None` if all items /// have been consumed. fn next<S: Into<Supercow<'a, Self>>>(s: S) -> Option<T> - where Self: Sized + 'a; + where + Self: Sized + 'a; } - diff --git a/tests/main.rs b/tests/main.rs index 512aa84..4a81792 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -1,19 +1,20 @@ -extern crate notmuch; extern crate dirs; +extern crate notmuch; use std::sync::Arc; +use notmuch::{Query, QueryExt, Thread, Threads}; use notmuch::{StreamingIterator, StreamingIteratorExt}; -use notmuch::{Threads, Thread, Query, QueryExt}; fn main() { - let mut mail_path = dirs::home_dir().unwrap(); mail_path.push(".mail"); - match notmuch::Database::open(&mail_path.to_str().unwrap().to_string(), notmuch::DatabaseMode::ReadOnly){ + match notmuch::Database::open( + &mail_path.to_str().unwrap().to_string(), + notmuch::DatabaseMode::ReadOnly, + ) { Ok(db) => { - #[cfg(feature = "v0_21")] { let rev = db.revision(); @@ -25,23 +26,20 @@ fn main() { notmuch::Query::create(dbr.clone(), &"".to_string()).unwrap() }; - // let mut threads = query.search_threads().unwrap(); - - // let mut threads = db.create_query(&"".to_string()).unwrap().search_threads().unwrap(); let threads = Arc::new(<Query as QueryExt>::search_threads(query).unwrap()); - - while let Some(thread) = <Threads<Query> as StreamingIteratorExt<Thread<Threads<Query>>>>::next(threads.clone()) { + while let Some(thread) = <Threads<Query> as StreamingIteratorExt< + Thread<Threads<Query>>, + >>::next(threads.clone()) + { println!("thread {:?} {:?}", thread.subject(), thread.authors()); } - - - }, - Err(err) =>{ + } + Err(err) => { println!("Got error while trying to open db: {:?}", err); } } |
