-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lifetimes and ownership on keys and values could use more elaboration #941
Comments
I am having a hard time coming up with all of these in |
I don't think this is possible generically, the problem being that impl Value for Bincode<T> where T: for<'a> Deserialize<'a> {
type SelfType<'a> = T;
fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a> {
let val = bincode::deserialize(data)?;
Ok(val)
}
...
} cannot unify an unnameable lifetime inside There is no problem though when #[derive(Deserialize)]
struct Foo<'a> {
bar: &'a str,
}
impl Value for Foo<'_> {
type SelfType<'a> = Foo<'a>;
fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a> {
let val = bincode::deserialize(data)?;
Ok(val)
}
...
} |
(I think this can be made to work by having users of your library implement a custom GAT variant of |
@adamreichold Huh. I wasn't expecting anyone to actually be looking into Today I wrote a little cheatsheet ensuring I actually understand the problem. In I actually "solved" the issue by using |
If you look at the current https://docs.rs/redb/latest/redb/index.html
The example uses
&str
:and that's quite confusing.
TableDefinition
mantions:And that's about all the explanation given.
It's unclear if the example could use
TableDefinition<String, u64>
. Is this OK? Worse? Better? etc. Does the whole example work because only string literals are used?Ideally some examples of avoiding copying etc. could be given as well. E.g. someone might have:
and might want to avoid cloning
big_value
just to create a key to do a lookup, so I think using:with some
#[repr(transparent)]
andtransmute
etc. might allow it, but it's actually very confusing and hard to come up with, especially in the presence of yet another component with it's own generics etc.The text was updated successfully, but these errors were encountered: