It's all day I'm stuck on this:
pub fn load<'k, K, V>(&self, key: K) -> Result<Option<V>, Error> where
K: 'k + Key<'k>,
V: 'k + Persistent + Debug + Serialize + for<'de> Deserialize<'de>,
{
let bucket = self.store
.bucket::<K,Bincode<V>>(Some(V::bucket_name()))?;
bucket
.get(key)?
.map_or(Ok(None), |data| Ok(Some(data.0)))
}
rust compiler output:
error[E0597]: `bucket` does not live long enough
--> src/persist.rs:35:9
|
29 | pub fn load<'k, K, V>(&self, key: K) -> Result<Option<V>, Error> where
| -- lifetime `'k` defined here
...
35 | bucket
| -^^^^^
| |
| _________borrowed value does not live long enough
| |
36 | | .get(key)?
| |_____________________- argument requires that `bucket` is borrowed for `'k`
37 | .map_or(Ok(None), |data| Ok(Some(data.0)))
38 | }
| - `bucket` dropped here while still borrowed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.
error: could not compile `disyer`
To learn more, run the command again with --verbose.
I tried almost everything even using Higher-Rank Trait Bounds (HRTBs) without success.
Replacing K with a concrete type (like &str) works perfectly but I want the method to work with generics (like the bucket.get() function I'm calling does).
The library I'm writing aims to be a simple wrapper around kv crate.