I have the following thing that I’m searching a nice abstraction for: in leveldb (http://github.com/skade/leveldb), keys handled as ptr+length (slice). But they may represent complex data, e.g. encoding a key and it’s type.

Previously, I used a hand-rolled trait for that:

/// this is very old-school pub trait Key { fn from_u8(key: &[u8]) -> Self; fn as_slice<T, F: Fn(&[u8]) -> T>(&self, f: F) -> T; }

I now try to express it through convert :

pub trait Key<'a> : From<&'a [u8]> + AsRef<[u8]>

Now, I have the problem of a very unwieldy lifetime. Is there any way to avoid this?