aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorC. Morgan Hamill <me@cmhamill.org>2015-03-20 18:31:22 +0100
committerC. Morgan Hamill <me@cmhamill.org>2015-03-20 18:31:22 +0100
commit95d4fba8436417a6c27522ed9b51c19a9fd7c6f9 (patch)
tree207ec286049f158bfba74d892f8b0cbd56a60310 /src
parent08a7366e0e561160a2b5a1dc01330f3f7f467469 (diff)
downloadmail-95d4fba8436417a6c27522ed9b51c19a9fd7c6f9.tar.gz
Make `to_str()` method generic over lifetime.
If I have this correct: The output `&str` will have the same lifetime as whatever the lifetime of the block in which it is called. This allows using it one the output of notmuch FFI calls, by propogating the lifetime of the safe wrapper object (e.g., `Database`) to the `&str` returned from `to_str()`. This mirrors the lifetime of the actual underlying C string. If I don't grok lifetimes as well as I think, this could be a lie. Future self: you should add unit tests to test the above explanation.
Diffstat (limited to 'src')
-rw-r--r--src/ffi.rs2
-rw-r--r--src/utils.rs4
2 files changed, 3 insertions, 3 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
index 45a1f17..5f71778 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -67,7 +67,7 @@ impl notmuch_status_t {
}
impl ToStr for NotmuchStatus {
- fn to_str(&self) -> Result<&str, str::Utf8Error> {
+ fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> {
unsafe {
notmuch_status_to_string(self.to_notmuch_t())
}.to_static_str()
diff --git a/src/utils.rs b/src/utils.rs
index 7e17ab9..dbabe21 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -25,11 +25,11 @@ impl<T: ffi::AsOsStr> ToCString for T {
}
pub trait ToStr {
- fn to_str(&self) -> Result<&str, str::Utf8Error>;
+ fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error>;
}
impl ToStr for *const libc::c_char {
- fn to_str(&self) -> Result<&str, str::Utf8Error> {
+ fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(unsafe {
ffi::CStr::from_ptr(*self)
}.to_bytes())