diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-04 21:11:59 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-04 21:11:59 +0100 |
| commit | 228e7665bc4dc20929ea2a8cb52600da3d4dd839 (patch) | |
| tree | 8ec41c3fc3db0c470c717befa08568010d2bed7f | |
| parent | 08aa3be11a25c8ccbdf4806a4a08c9267cae9140 (diff) | |
| download | mail-228e7665bc4dc20929ea2a8cb52600da3d4dd839.tar.gz | |
add MessageExt trait
| -rw-r--r-- | src/database.rs | 5 | ||||
| -rw-r--r-- | src/directory.rs | 4 | ||||
| -rw-r--r-- | src/message.rs | 22 | ||||
| -rw-r--r-- | src/query.rs | 1 | ||||
| -rw-r--r-- | src/tags.rs | 5 | ||||
| -rw-r--r-- | src/thread.rs | 4 | ||||
| -rw-r--r-- | src/threads.rs | 4 | ||||
| -rw-r--r-- | tests/main.rs | 8 |
8 files changed, 49 insertions, 4 deletions
diff --git a/src/database.rs b/src/database.rs index 67ed3da..8a125b4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -238,5 +238,10 @@ impl Database { } } +pub trait DatabaseExt{ + +} + + unsafe impl Send for Database {} unsafe impl Sync for Database {} diff --git a/src/directory.rs b/src/directory.rs index c179eb8..8ddc044 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -72,5 +72,9 @@ impl<'d> Directory<'d> { } } +pub trait DirectoryExt<'d>{ + +} + unsafe impl<'d> Send for Directory<'d> {} unsafe impl<'d> Sync for Directory<'d> {} diff --git a/src/message.rs b/src/message.rs index ed72997..f825e03 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::Phantomcow; +use supercow::{Supercow, Phantomcow}; use error::{Error, Result}; use ffi; @@ -131,5 +131,25 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } } + +pub trait MessageExt<'o, Owner: MessageOwner + 'o>{ + + fn replies<'s, M: Into<Supercow<'s, Message<'o, Owner>>>>(message: M) -> Messages<'s, Message<'o, Owner>> { + let messageref = message.into(); + Messages::from_ptr( + unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) }, + Supercow::phantom(messageref) + ) + } + + fn filenames<'s, M: Into<Supercow<'s, Message<'o, Owner>>>>(message: M) -> Filenames<'s, Message<'o, Owner>> { + let messageref = message.into(); + Filenames::from_ptr( + unsafe { ffi::notmuch_message_get_filenames(messageref.handle.ptr) }, + Supercow::phantom(messageref) + ) + } +} + 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/query.rs b/src/query.rs index 7cf940c..4839f3b 100644 --- a/src/query.rs +++ b/src/query.rs @@ -94,7 +94,6 @@ 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_messages<'q, Q: Into<Supercow<'q, Query<'d>>>>(query: Q) -> Result<Messages<'q, Query<'d>>>; - } impl<'d> QueryExt<'d> for Query<'d>{ diff --git a/src/tags.rs b/src/tags.rs index 187e26c..243cfbc 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -58,5 +58,10 @@ impl<'o, Owner: TagsOwner + 'o> Iterator for Tags<'o, Owner> { } } + +pub trait TagsExt<'o, Owner: TagsOwner + 'o>{ + +} + 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 c112e06..36da638 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -106,5 +106,9 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { } } +pub trait ThreadExt<'o, Owner: ThreadOwner + 'o>{ + +} + 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 6dfa047..bf869ab 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -69,5 +69,9 @@ impl<'s, 'o: 's, Owner: ThreadsOwner + 'o> StreamingIterator<'s, Thread<'s, Self } } +pub trait ThreadsExt<'o, Owner: ThreadsOwner + 'o>{ + +} + unsafe impl<'o, Owner: ThreadsOwner + 'o> Send for Threads<'o, Owner> {} unsafe impl<'o, Owner: ThreadsOwner + 'o> Sync for Threads<'o, Owner> {} diff --git a/tests/main.rs b/tests/main.rs index fd7e511..11723b2 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -4,6 +4,7 @@ extern crate dirs; use std::sync::Arc; use notmuch::StreamingIterator; +use notmuch::{Query, QueryExt}; fn main() { @@ -25,11 +26,14 @@ fn main() { }; - let mut threads = query.search_threads().unwrap(); + // let mut threads = query.search_threads().unwrap(); - //let mut threads = db.create_query(&"".to_string()).unwrap().search_threads().unwrap(); + // let mut threads = db.create_query(&"".to_string()).unwrap().search_threads().unwrap(); + + let mut threads = <Query as QueryExt>::search_threads(query).unwrap(); + while let Some(thread) = threads.next() { println!("thread {:?} {:?}", thread.subject(), thread.authors()); |
