diff options
| author | C. Morgan Hamill <me@cmhamill.org> | 2015-03-20 13:46:32 +0100 |
|---|---|---|
| committer | C. Morgan Hamill <me@cmhamill.org> | 2015-03-20 13:58:59 +0100 |
| commit | d3f5ca027545db5c0e54ceb758bcd4e27e2ce003 (patch) | |
| tree | 5d8a27b7df16077f2aeb083250451677ed8615bb | |
| parent | fb76ee5ec2368c6f36d8a4f73234e614ee6ca0d0 (diff) | |
| download | mail-d3f5ca027545db5c0e54ceb758bcd4e27e2ce003.tar.gz | |
Implement `Error` for `NotmuchStatus`.
Entails implementation of `ToStr` and `Display`, also.
Note that the `to_str()` method uses the `to_static_str()` method on the
`ToStaticStr` trait internally --- this is how I expect to use the
latter. This lets me provide a uniform `to_str()` method in the rest of
the API, while transparently handling the differences between C string
lifetimes.
| -rw-r--r-- | src/ffi.rs | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -11,7 +11,17 @@ use libc::{ time_t, }; -use utils::NotmuchEnum; +use std::{ + error, + fmt, + str, +}; + +use utils::{ + NotmuchEnum, + ToStaticStr, + ToStr, +}; pub type notmuch_bool_t = c_int; @@ -56,6 +66,26 @@ impl notmuch_status_t { } } +impl ToStr for NotmuchStatus { + fn to_str(&self) -> Result<&str, str::Utf8Error> { + unsafe { + notmuch_status_to_string(self.to_notmuch_t()) + }.to_static_str() + } +} + +impl fmt::Display for NotmuchStatus { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.to_str().unwrap()) + } +} + +impl error::Error for NotmuchStatus { + fn description(&self) -> &str { + self.to_str().unwrap() + } +} + notmuch_enum! { #[repr(C)] #[derive(Copy, Debug)] |
