diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-12 21:05:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-12 21:05:36 +0100 |
| commit | ad70f33648245764c2d02bde14207f9b86bfe016 (patch) | |
| tree | bef4b10c329d66fde11e4eea8b1300fd7cb2385a | |
| parent | 9dad03a829708985a8ff9428c176decd1679ca51 (diff) | |
| parent | ba03b994b3318c84923f4a9a23cfc4270a5ace75 (diff) | |
| download | mail-ad70f33648245764c2d02bde14207f9b86bfe016.tar.gz | |
Merge pull request #10 from eaon/master
Switch to more legible `where` syntax
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | src/database.rs | 86 | ||||
| -rw-r--r-- | src/directory.rs | 15 | ||||
| -rw-r--r-- | src/filenames.rs | 29 | ||||
| -rw-r--r-- | src/message.rs | 66 | ||||
| -rw-r--r-- | src/messages.rs | 56 | ||||
| -rw-r--r-- | src/query.rs | 35 | ||||
| -rw-r--r-- | src/tags.rs | 30 | ||||
| -rw-r--r-- | src/thread.rs | 64 | ||||
| -rw-r--r-- | src/threads.rs | 49 |
10 files changed, 271 insertions, 163 deletions
@@ -38,8 +38,8 @@ fn main() { let mut mail_path = std::env::home_dir().unwrap(); mail_path.push(".mail"); - let db = notmuch::Database::open(&mail_path.to_str().unwrap().to_string(), notmuch::DatabaseMode::ReadOnly).unwrap(); - let query = db.create_query(&"".to_string()).unwrap(); + let db = notmuch::Database::open(&mail_path, notmuch::DatabaseMode::ReadOnly).unwrap(); + let query = db.create_query("").unwrap(); let mut threads = query.search_threads().unwrap(); while let Some(thread) = threads.next() { diff --git a/src/database.rs b/src/database.rs index c5cb917..d5e6700 100644 --- a/src/database.rs +++ b/src/database.rs @@ -57,7 +57,10 @@ pub struct Database { impl TagsOwner for Database {} impl Database { - pub fn create<P: AsRef<Path>>(path: &P) -> Result<Self> { + pub fn create<P>(path: &P) -> Result<Self> + where + P: AsRef<Path>, + { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); @@ -68,7 +71,10 @@ impl Database { }) } - pub fn open<P: AsRef<Path>>(path: &P, mode: DatabaseMode) -> Result<Self> { + pub fn open<P>(path: &P, mode: DatabaseMode) -> Result<Self> + where + P: AsRef<Path>, + { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); @@ -88,27 +94,28 @@ impl Database { Ok(()) } - pub fn compact<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - ) -> Result<()> { + pub fn compact<P, F>(path: &P, backup_path: Option<&P>) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { let status: Option<F> = None; Database::_compact(path, backup_path, status) } - pub fn compact_with_status<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: F, - ) -> Result<()> { + pub fn compact_with_status<P, F>(path: &P, backup_path: Option<&P>, status: F) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { Database::_compact(path, backup_path, Some(status)) } - fn _compact<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: Option<F>, - ) -> Result<()> { + fn _compact<P, F>(path: &P, backup_path: Option<&P>, status: Option<F>) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { extern "C" fn wrapper<F: FnMut(&str)>( message: *const libc::c_char, closure: *mut libc::c_void, @@ -174,18 +181,30 @@ impl Database { unsafe { ffi::notmuch_database_needs_upgrade(self.handle.ptr) == 1 } } - pub fn upgrade<F: FnMut(f64)>(&mut self) -> Result<()> { + pub fn upgrade<F>(&mut self) -> Result<()> + where + F: FnMut(f64), + { let status: Option<F> = None; self._upgrade(status) } - pub fn upgrade_with_status<F: FnMut(f64)>(&mut self, status: F) -> Result<()> { + pub fn upgrade_with_status<F>(&mut self, status: F) -> Result<()> + where + F: FnMut(f64), + { self._upgrade(Some(status)) } - fn _upgrade<F: FnMut(f64)>(&mut self, status: Option<F>) -> Result<()> { + fn _upgrade<F>(&mut self, status: Option<F>) -> Result<()> + where + F: FnMut(f64), + { #[allow(trivial_numeric_casts)] - extern "C" fn wrapper<F: FnMut(f64)>(closure: *mut libc::c_void, progress: libc::c_double) { + extern "C" fn wrapper<F>(closure: *mut libc::c_void, progress: libc::c_double) + where + F: FnMut(f64), + { let closure = closure as *mut F; unsafe { (*closure)(progress as f64) } } @@ -208,7 +227,10 @@ impl Database { Ok(()) } - pub fn directory<'d, P: AsRef<Path>>(&'d self, path: &P) -> Result<Option<Directory<'d>>> { + pub fn directory<'d, P>(&'d self, path: &P) -> Result<Option<Directory<'d>>> + where + P: AsRef<Path>, + { <Self as DatabaseExt>::directory(self, path) } @@ -222,10 +244,10 @@ impl Database { } pub trait DatabaseExt { - fn create_query<'d, D: Into<Supercow<'d, Database>>>( - database: D, - query_string: &str, - ) -> Result<Query<'d>> { + fn create_query<'d, D>(database: D, query_string: &str) -> Result<Query<'d>> + where + D: Into<Supercow<'d, Database>>, + { let dbref = database.into(); let query_str = CString::new(query_string).unwrap(); @@ -234,7 +256,10 @@ pub trait DatabaseExt { Ok(Query::from_ptr(query, Supercow::phantom(dbref))) } - fn all_tags<'d, D: Into<Supercow<'d, Database>>>(database: D) -> Result<Tags<'d, Database>> { + fn all_tags<'d, D>(database: D) -> Result<Tags<'d, Database>> + where + D: Into<Supercow<'d, Database>>, + { let dbref = database.into(); let tags = unsafe { ffi::notmuch_database_get_all_tags(dbref.handle.ptr) }; @@ -242,10 +267,11 @@ 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, P>(database: D, path: &P) -> Result<Option<Directory<'d>>> + where + D: Into<Supercow<'d, Database>>, + P: AsRef<Path>, + { let dbref = database.into(); let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); diff --git a/src/directory.rs b/src/directory.rs index c2bb88d..e3abcf5 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -26,10 +26,10 @@ pub struct Directory<'d> { impl<'d> FilenamesOwner for Directory<'d> {} impl<'d> Directory<'d> { - pub fn from_ptr<O: Into<Phantomcow<'d, Database>>>( - ptr: *mut ffi::notmuch_directory_t, - owner: O, - ) -> Directory<'d> { + pub fn from_ptr<O>(ptr: *mut ffi::notmuch_directory_t, owner: O) -> Directory<'d> + where + O: Into<Phantomcow<'d, Database>>, + { Directory { handle: DirectoryPtr { ptr }, marker: owner.into(), @@ -42,9 +42,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>> { + fn child_directories<'s, S>(directory: S) -> Filenames<'s, Directory<'d>> + where + S: Into<Supercow<'s, Directory<'d>>>, + { let dir = directory.into(); Filenames::from_ptr( unsafe { ffi::notmuch_directory_get_child_directories(dir.handle.ptr) }, diff --git a/src/filenames.rs b/src/filenames.rs index ae90280..3eef82d 100644 --- a/src/filenames.rs +++ b/src/filenames.rs @@ -25,16 +25,22 @@ impl Drop for FilenamesPtr { } #[derive(Debug)] -pub struct Filenames<'o, Owner: FilenamesOwner + 'o> { +pub struct Filenames<'o, O> +where + O: FilenamesOwner + 'o, +{ pub(crate) handle: FilenamesPtr, - pub(crate) marker: Phantomcow<'o, Owner>, + pub(crate) marker: Phantomcow<'o, O>, } -impl<'o, Owner: FilenamesOwner + 'o> Filenames<'o, Owner> { - pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_filenames_t, - owner: O, - ) -> Filenames<'o, Owner> { +impl<'o, O> Filenames<'o, O> +where + O: FilenamesOwner + 'o, +{ + pub fn from_ptr<P>(ptr: *mut ffi::notmuch_filenames_t, owner: P) -> Filenames<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Filenames { handle: FilenamesPtr { ptr }, marker: owner.into(), @@ -42,7 +48,10 @@ impl<'o, Owner: FilenamesOwner + 'o> Filenames<'o, Owner> { } } -impl<'o, Owner: FilenamesOwner + 'o> Iterator for Filenames<'o, Owner> { +impl<'o, O> Iterator for Filenames<'o, O> +where + O: FilenamesOwner + 'o, +{ type Item = PathBuf; fn next(self: &mut Self) -> Option<Self::Item> { @@ -62,5 +71,5 @@ impl<'o, Owner: FilenamesOwner + 'o> Iterator for Filenames<'o, Owner> { } } -unsafe impl<'o, Owner: FilenamesOwner + 'o> Send for Filenames<'o, Owner> {} -unsafe impl<'o, Owner: FilenamesOwner + 'o> Sync for Filenames<'o, Owner> {} +unsafe impl<'o, O> Send for Filenames<'o, O> where O: FilenamesOwner + 'o {} +unsafe impl<'o, O> Sync for Filenames<'o, O> where O: FilenamesOwner + 'o {} diff --git a/src/message.rs b/src/message.rs index 4b3c92f..b253d68 100644 --- a/src/message.rs +++ b/src/message.rs @@ -28,20 +28,26 @@ impl Drop for MessagePtr { } #[derive(Debug)] -pub struct Message<'o, Owner: MessageOwner + 'o> { +pub struct Message<'o, O> +where + O: MessageOwner + 'o, +{ pub(crate) handle: MessagePtr, - marker: Phantomcow<'o, Owner>, + marker: Phantomcow<'o, O>, } -impl<'o, Owner: MessageOwner + 'o> MessagesOwner for Message<'o, Owner> {} -impl<'o, Owner: MessageOwner + 'o> FilenamesOwner for Message<'o, Owner> {} -impl<'o, Owner: MessageOwner + 'o> TagsOwner for Message<'o, Owner> {} - -impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { - pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_message_t, - owner: O, - ) -> Message<'o, Owner> { +impl<'o, O> MessagesOwner for Message<'o, O> where O: MessageOwner + 'o {} +impl<'o, O> FilenamesOwner for Message<'o, O> where O: MessageOwner + 'o {} +impl<'o, O> TagsOwner for Message<'o, O> where O: MessageOwner + 'o {} + +impl<'o, O> Message<'o, O> +where + O: MessageOwner + 'o, +{ + pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Message { handle: MessagePtr { ptr }, marker: owner.into(), @@ -59,7 +65,7 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } pub fn replies(self: &Self) -> Messages<Self> { - <Self as MessageExt<'o, Owner>>::replies(self) + <Self as MessageExt<'o, O>>::replies(self) } #[cfg(feature = "v0_26")] @@ -68,7 +74,7 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } pub fn filenames(self: &Self) -> Filenames<Self> { - <Self as MessageExt<'o, Owner>>::filenames(self) + <Self as MessageExt<'o, O>>::filenames(self) } pub fn filename(self: &Self) -> PathBuf { @@ -97,7 +103,7 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } pub fn tags(&self) -> Tags<Self> { - <Self as MessageExt<'o, Owner>>::tags(self) + <Self as MessageExt<'o, O>>::tags(self) } pub fn add_tag(self: &Self, tag: &str) -> Status { @@ -115,10 +121,14 @@ impl<'o, Owner: MessageOwner + 'o> 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>> { +pub trait MessageExt<'o, O> +where + O: MessageOwner + 'o, +{ + fn tags<'s, S>(message: S) -> Tags<'s, Message<'o, O>> + where + S: Into<Supercow<'s, Message<'o, O>>>, + { let messageref = message.into(); Tags::from_ptr( unsafe { ffi::notmuch_message_get_tags(messageref.handle.ptr) }, @@ -126,9 +136,10 @@ pub trait MessageExt<'o, Owner: MessageOwner + 'o> { ) } - fn replies<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>( - message: S, - ) -> Messages<'s, Message<'o, Owner>> { + fn replies<'s, S>(message: S) -> Messages<'s, Message<'o, O>> + where + S: Into<Supercow<'s, Message<'o, O>>>, + { let messageref = message.into(); Messages::from_ptr( unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) }, @@ -136,9 +147,10 @@ pub trait MessageExt<'o, Owner: MessageOwner + 'o> { ) } - fn filenames<'s, S: Into<Supercow<'s, Message<'o, Owner>>>>( - message: S, - ) -> Filenames<'s, Message<'o, Owner>> { + fn filenames<'s, S>(message: S) -> Filenames<'s, Message<'o, O>> + where + S: Into<Supercow<'s, Message<'o, O>>>, + { let messageref = message.into(); Filenames::from_ptr( unsafe { ffi::notmuch_message_get_filenames(messageref.handle.ptr) }, @@ -147,7 +159,7 @@ pub trait MessageExt<'o, Owner: MessageOwner + 'o> { } } -impl<'o, Owner: MessageOwner + 'o> MessageExt<'o, Owner> for Message<'o, Owner> {} +impl<'o, O> MessageExt<'o, O> for Message<'o, O> where O: MessageOwner + 'o {} -unsafe impl<'o, Owner: MessageOwner + 'o> Send for Message<'o, Owner> {} -unsafe impl<'o, Owner: MessageOwner + 'o> Sync for Message<'o, Owner> {} +unsafe impl<'o, O> Send for Message<'o, O> where O: MessageOwner + 'o {} +unsafe impl<'o, O> Sync for Message<'o, O> where O: MessageOwner + 'o {} diff --git a/src/messages.rs b/src/messages.rs index 34a9bb5..5977e42 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -29,16 +29,22 @@ impl Drop for MessagesPtr { } #[derive(Debug)] -pub struct Messages<'o, Owner: MessagesOwner + 'o> { +pub struct Messages<'o, O> +where + O: MessagesOwner + 'o, +{ pub(crate) handle: MessagesPtr, - marker: Phantomcow<'o, Owner>, + marker: Phantomcow<'o, O>, } -impl<'o, Owner: MessagesOwner + 'o> Messages<'o, Owner> { - pub(crate) fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_messages_t, - owner: O, - ) -> Messages<'o, Owner> { +impl<'o, O> Messages<'o, O> +where + O: MessagesOwner + 'o, +{ + pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Messages { handle: MessagesPtr { ptr }, marker: owner.into(), @@ -46,10 +52,13 @@ impl<'o, Owner: MessagesOwner + 'o> Messages<'o, Owner> { } } -impl<'o, Owner: MessagesOwner + 'o> MessageOwner for Messages<'o, Owner> {} -impl<'o, Owner: MessagesOwner + 'o> TagsOwner for Messages<'o, Owner> {} +impl<'o, O> MessageOwner for Messages<'o, O> where O: MessagesOwner + 'o {} +impl<'o, O> TagsOwner for Messages<'o, O> where O: MessagesOwner + 'o {} -impl<'o, Owner: MessagesOwner + 'o> Messages<'o, Owner> { +impl<'o, O> Messages<'o, O> +where + O: MessagesOwner + 'o, +{ /** * Return a list of tags from all messages. * @@ -71,22 +80,31 @@ impl<'o, Owner: MessagesOwner + 'o> Messages<'o, Owner> { } } -impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIterator<'s, Message<'s, Self>> - for Messages<'o, Owner> +impl<'s, 'o: 's, O> StreamingIterator<'s, Message<'s, Self>> for Messages<'o, O> +where + O: MessagesOwner + 'o, { fn next(&'s mut self) -> Option<Message<'s, Self>> { <Self as StreamingIteratorExt<'s, Message<'s, Self>>>::next(Supercow::borrowed(self)) } } -pub trait MessagesExt<'o, Owner: MessagesOwner + 'o> {} +pub trait MessagesExt<'o, O> +where + O: MessagesOwner + 'o, +{ +} -impl<'o, Owner: MessagesOwner + 'o> MessagesExt<'o, Owner> for Messages<'o, Owner> {} +impl<'o, O> MessagesExt<'o, O> for Messages<'o, O> where O: MessagesOwner + 'o {} -impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIteratorExt<'s, Message<'s, Self>> - for Messages<'o, Owner> +impl<'s, 'o: 's, O> StreamingIteratorExt<'s, Message<'s, Self>> for Messages<'o, O> +where + O: MessagesOwner + 'o, { - fn next<S: Into<Supercow<'s, Messages<'o, Owner>>>>(messages: S) -> Option<Message<'s, Self>> { + fn next<S>(messages: S) -> Option<Message<'s, Self>> + where + S: Into<Supercow<'s, Messages<'o, O>>>, + { let messagesref = messages.into(); let valid = unsafe { ffi::notmuch_messages_valid(messagesref.handle.ptr) }; @@ -104,5 +122,5 @@ impl<'s, 'o: 's, Owner: MessagesOwner + 'o> StreamingIteratorExt<'s, Message<'s, } } -unsafe impl<'o, Owner: MessagesOwner + 'o> Send for Messages<'o, Owner> {} -unsafe impl<'o, Owner: MessagesOwner + 'o> Sync for Messages<'o, Owner> {} +unsafe impl<'o, O> Send for Messages<'o, O> where O: MessagesOwner + 'o {} +unsafe impl<'o, O> Sync for Messages<'o, O> where O: MessagesOwner + 'o {} diff --git a/src/query.rs b/src/query.rs index 95a4d56..c73d4ca 100644 --- a/src/query.rs +++ b/src/query.rs @@ -33,27 +33,30 @@ 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> { + pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_query_t, owner: O) -> Query<'d> + where + O: Into<Phantomcow<'d, Database>>, + { Query { handle: QueryPtr { ptr }, marker: owner.into(), } } - pub(crate) fn from_handle<O: Into<Phantomcow<'d, Database>>>( - handle: QueryPtr, - owner: O, - ) -> Query<'d> { + pub(crate) fn from_handle<O>(handle: QueryPtr, owner: O) -> Query<'d> + where + O: Into<Phantomcow<'d, Database>>, + { Query { handle, marker: owner.into(), } } - pub fn create<D: Into<Supercow<'d, Database>>>(db: D, query_string: &str) -> Result<Self> { + pub fn create<D>(db: D, query_string: &str) -> Result<Self> + where + D: Into<Supercow<'d, Database>>, + { let dbref = db.into(); dbref .handle @@ -97,9 +100,10 @@ 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>>> { + fn search_threads<'q, Q>(query: Q) -> Result<Threads<'q, Query<'d>>> + where + Q: Into<Supercow<'q, Query<'d>>>, + { let queryref = query.into(); let mut thrds = ptr::null_mut(); @@ -111,9 +115,10 @@ pub trait QueryExt<'d> { 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>(query: Q) -> Result<Messages<'q, Query<'d>>> + where + Q: Into<Supercow<'q, Query<'d>>>, + { let queryref = query.into(); let mut msgs = ptr::null_mut(); diff --git a/src/tags.rs b/src/tags.rs index 573a491..96afdf6 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -25,11 +25,14 @@ pub struct Tags<'o, Owner: TagsOwner + 'o> { marker: Phantomcow<'o, Owner>, } -impl<'o, Owner: TagsOwner + 'o> Tags<'o, Owner> { - pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_tags_t, - owner: O, - ) -> Tags<'o, Owner> { +impl<'o, O> Tags<'o, O> +where + O: TagsOwner + 'o, +{ + pub fn from_ptr<P>(ptr: *mut ffi::notmuch_tags_t, owner: P) -> Tags<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Tags { handle: TagsPtr { ptr }, marker: owner.into(), @@ -37,7 +40,10 @@ impl<'o, Owner: TagsOwner + 'o> Tags<'o, Owner> { } } -impl<'o, Owner: TagsOwner + 'o> Iterator for Tags<'o, Owner> { +impl<'o, O> Iterator for Tags<'o, O> +where + O: TagsOwner + 'o, +{ type Item = String; fn next(&mut self) -> Option<Self::Item> { @@ -58,9 +64,13 @@ impl<'o, Owner: TagsOwner + 'o> Iterator for Tags<'o, Owner> { } } -pub trait TagsExt<'o, Owner: TagsOwner + 'o> {} +pub trait TagsExt<'o, O> +where + O: TagsOwner + 'o, +{ +} -impl<'o, Owner: TagsOwner + 'o> TagsExt<'o, Owner> for Tags<'o, Owner> {} +impl<'o, O> TagsExt<'o, O> for Tags<'o, O> where O: TagsOwner + 'o {} -unsafe impl<'o, Owner: TagsOwner + 'o> Send for Tags<'o, Owner> {} -unsafe impl<'o, Owner: TagsOwner + 'o> Sync for Tags<'o, Owner> {} +unsafe impl<'o, O> Send for Tags<'o, O> where O: TagsOwner + 'o {} +unsafe impl<'o, O> Sync for Tags<'o, O> where O: TagsOwner + 'o {} diff --git a/src/thread.rs b/src/thread.rs index a529508..fce026d 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -22,19 +22,25 @@ impl Drop for ThreadPtr { } #[derive(Debug)] -pub struct Thread<'o, Owner: ThreadOwner + 'o> { +pub struct Thread<'o, O> +where + O: ThreadOwner + 'o, +{ pub(crate) handle: ThreadPtr, - marker: Phantomcow<'o, Owner>, + marker: Phantomcow<'o, O>, } -impl<'o, Owner: ThreadOwner + 'o> MessagesOwner for Thread<'o, Owner> {} -impl<'o, Owner: ThreadOwner + 'o> TagsOwner for Thread<'o, Owner> {} - -impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { - pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_thread_t, - owner: O, - ) -> Thread<'o, Owner> { +impl<'o, O> MessagesOwner for Thread<'o, O> where O: ThreadOwner + 'o {} +impl<'o, O> TagsOwner for Thread<'o, O> where O: ThreadOwner + 'o {} + +impl<'o, O> Thread<'o, O> +where + O: ThreadOwner + 'o, +{ + pub fn from_ptr<P>(ptr: *mut ffi::notmuch_thread_t, owner: P) -> Thread<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Thread { handle: ThreadPtr { ptr }, marker: owner.into(), @@ -56,17 +62,17 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { } pub fn toplevel_messages(self: &Self) -> Messages<Self> { - <Self as ThreadExt<'o, Owner>>::toplevel_messages(self) + <Self as ThreadExt<'o, O>>::toplevel_messages(self) } /// Get a `Messages` iterator for all messages in 'thread' in /// oldest-first order. pub fn messages(self: &Self) -> Messages<Self> { - <Self as ThreadExt<'o, Owner>>::messages(self) + <Self as ThreadExt<'o, O>>::messages(self) } pub fn tags(&self) -> Tags<Self> { - <Self as ThreadExt<'o, Owner>>::tags(self) + <Self as ThreadExt<'o, O>>::tags(self) } pub fn subject(self: &Self) -> String { @@ -97,10 +103,14 @@ 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, O> +where + O: ThreadOwner + 'o, +{ + fn tags<'s, S>(thread: S) -> Tags<'s, Thread<'o, O>> + where + S: Into<Supercow<'s, Thread<'o, O>>>, + { let threadref = thread.into(); Tags::from_ptr( unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) }, @@ -108,9 +118,10 @@ pub trait ThreadExt<'o, Owner: ThreadOwner + 'o> { ) } - fn toplevel_messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>( - thread: S, - ) -> Messages<'s, Thread<'o, Owner>> { + fn toplevel_messages<'s, S>(thread: S) -> Messages<'s, Thread<'o, O>> + where + S: Into<Supercow<'s, Thread<'o, O>>>, + { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) }, @@ -120,9 +131,10 @@ pub trait ThreadExt<'o, Owner: ThreadOwner + 'o> { /// 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>(thread: S) -> Messages<'s, Thread<'o, O>> + where + S: Into<Supercow<'s, Thread<'o, O>>>, + { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) }, @@ -131,7 +143,7 @@ pub trait ThreadExt<'o, Owner: ThreadOwner + 'o> { } } -impl<'o, Owner: ThreadOwner + 'o> ThreadExt<'o, Owner> for Thread<'o, Owner> {} +impl<'o, O> ThreadExt<'o, O> for Thread<'o, O> where O: ThreadOwner + 'o {} -unsafe impl<'o, Owner: ThreadOwner + 'o> Send for Thread<'o, Owner> {} -unsafe impl<'o, Owner: ThreadOwner + 'o> Sync for Thread<'o, Owner> {} +unsafe impl<'o, O> Send for Thread<'o, O> where O: ThreadOwner + 'o {} +unsafe impl<'o, O> Sync for Thread<'o, O> where O: ThreadOwner + 'o {} diff --git a/src/threads.rs b/src/threads.rs index e2312c7..f99ffb1 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -21,18 +21,24 @@ impl Drop for ThreadsPtr { } #[derive(Debug)] -pub struct Threads<'o, Owner: ThreadsOwner + 'o> { +pub struct Threads<'o, O> +where + O: ThreadsOwner + 'o, +{ handle: ThreadsPtr, - marker: Phantomcow<'o, Owner>, + marker: Phantomcow<'o, O>, } -impl<'o, Owner: ThreadsOwner + 'o> ThreadOwner for Threads<'o, Owner> {} +impl<'o, O> ThreadOwner for Threads<'o, O> where O: ThreadsOwner + 'o {} -impl<'o, Owner: ThreadsOwner + 'o> Threads<'o, Owner> { - pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>( - ptr: *mut ffi::notmuch_threads_t, - owner: O, - ) -> Threads<'o, Owner> { +impl<'o, O> Threads<'o, O> +where + O: ThreadsOwner + 'o, +{ + pub fn from_ptr<P>(ptr: *mut ffi::notmuch_threads_t, owner: P) -> Threads<'o, O> + where + P: Into<Phantomcow<'o, O>>, + { Threads { handle: ThreadsPtr { ptr }, marker: owner.into(), @@ -40,22 +46,31 @@ impl<'o, Owner: ThreadsOwner + 'o> Threads<'o, Owner> { } } -impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIterator<'s, Thread<'s, Self>> - for Threads<'o, Owner> +impl<'s, 'o: 's, O> StreamingIterator<'s, Thread<'s, Self>> for Threads<'o, O> +where + O: ThreadsOwner + 'o, { fn next(&'s mut self) -> Option<Thread<'s, Self>> { <Self as StreamingIteratorExt<'s, Thread<'s, Self>>>::next(Supercow::borrowed(self)) } } -pub trait ThreadsExt<'o, Owner: ThreadsOwner + 'o> {} +pub trait ThreadsExt<'o, O> +where + O: ThreadsOwner + 'o, +{ +} -impl<'o, Owner: ThreadsOwner + 'o> ThreadsExt<'o, Owner> for Threads<'o, Owner> {} +impl<'o, O> ThreadsExt<'o, O> for Threads<'o, O> where O: ThreadsOwner + 'o {} -impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIteratorExt<'s, Thread<'s, Self>> - for Threads<'o, Owner> +impl<'s, 'o: 's, O> StreamingIteratorExt<'s, Thread<'s, Self>> for Threads<'o, O> +where + O: ThreadsOwner + 'o, { - fn next<S: Into<Supercow<'s, Threads<'o, Owner>>>>(threads: S) -> Option<Thread<'s, Self>> { + fn next<S>(threads: S) -> Option<Thread<'s, Self>> + where + S: Into<Supercow<'s, Threads<'o, O>>>, + { let threadsref = threads.into(); let valid = unsafe { ffi::notmuch_threads_valid(threadsref.handle.ptr) }; @@ -73,5 +88,5 @@ impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIteratorExt<'s, Thread<'s, S } } -unsafe impl<'o, Owner: ThreadsOwner + 'o> Send for Threads<'o, Owner> {} -unsafe impl<'o, Owner: ThreadsOwner + 'o> Sync for Threads<'o, Owner> {} +unsafe impl<'o, O> Send for Threads<'o, O> where O: ThreadsOwner + 'o {} +unsafe impl<'o, O> Sync for Threads<'o, O> where O: ThreadsOwner + 'o {} |
