From 95d4fba8436417a6c27522ed9b51c19a9fd7c6f9 Mon Sep 17 00:00:00 2001 From: "C. Morgan Hamill" Date: Fri, 20 Mar 2015 13:31:22 -0400 Subject: 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. --- src/ffi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ffi.rs') 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() -- cgit v1.2.1