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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
notmuch-rs
==========
This is not much more than a wrapper for the [notmuch](https://notmuchmail.org/) C api.
[](https://travis-ci.org/vhdirk/notmuch-rs)
[](https://crates.io/crates/notmuch)
[](https://crates.io/crates/notmuch)
[](https://crates.io/crates/notmuch)
## Building
**notmuch-rs** expects libnotmuch development files to be installed on your system.
## Using
Add this to your `Cargo.toml`:
```toml
[dependencies]
notmuch = "*"
```
and this to your crate root:
```rust
extern crate notmuch;
```
## Example
```rust
extern crate notmuch;
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 mut threads = query.search_threads().unwrap();
loop {
match threads.next() {
Some(thread) => {
println!("thread {:?} {:?}", thread.subject(), thread.authors());
},
None => { break }
}
}
}
```
## Concurrency
Notmuch makes no claims regarding thread safety. It does not seem to use any
thread locals, but I did not spot any locks. So, as far as I am concerned, it is
not thread safe.
So why do all structs implement ```Send``` and ```Sync```? Well, it _is_ safe to
access pointers from different threads (as long as you know what you are doing :) ).
But, more importantly, all structs are strictly linked together with their
lifetime. The root of the tree is ```notmuch::Database```, which has a lifetime
that must outlive any related objects, for instance ```notmuch::Query```. The
```notmuch::Threads``` iterator that you can get from a ```notmuch::Query``` is
always outlived by the parent query.
This means that you can only use these structs accross thread bounds if you
figure out how to satisfy the lifetime requirements. Up until now, I haven't
been able to do that (though my knowledge of Rust is still rather basic).
So, concurrency seems currently limited to scoped threads.
## Acknowledgements
notmuch-rs started out from the following projects:
- https://github.com/Stebalien/notmuch-sys/blob/master/src/lib.rs
- https://github.com/cmhamill/rust-notmuch
Any contributions are welcome!
|