Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upQueriable trait codegen breaks on explicit lifetimes #35
Comments
This comment has been minimized.
|
We wouldn't be able to query this out, as there would be no lifetime for us to deserialize |
This comment has been minimized.
|
We should improve the error message here though |
This comment has been minimized.
reem
commented
Nov 30, 2015
|
@sgrif on the other hand supporting lifetimes is important since there are types like |
This comment has been minimized.
|
You're right, that's a valid use case. (Just for the record, this was the code which I wrote to get my head straight) use std::borrow::{Cow, ToOwned};
impl<'a, T: ?Sized, ST> ToSql<ST> for Cow<'a, T> where
ST: NativeSqlType,
T: 'a + ToOwned + ToSql<ST>,
T::Owned: ToSql<ST>,
{
fn to_sql<W: Write>(&self, out: &mut W) -> Result<IsNull, Box<Error>> {
match self {
&Cow::Borrowed(ref t) => t.to_sql(out),
&Cow::Owned(ref t) => t.to_sql(out),
}
}
}
impl<'a, T: ?Sized, ST> FromSql<ST> for Cow<'a, T> where
ST: NativeSqlType,
T: 'a + ToOwned,
T::Owned: FromSql<ST>,
{
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<Error>> {
T::Owned::from_sql(bytes).map(Cow::Owned)
}
} |
This comment has been minimized.
|
I also need to properly support generic lifetimes for the other codegen as well, at the moment they just take advantage of the fact that you can have an unused lifetime name in an impl, and just put |
This comment has been minimized.
reem
commented
Nov 30, 2015
|
Does that actually compile? I would guess that in the FromSql implementation you'd need It's very tricky to get bounds correct in codegen, even the built-in derives are overly restrictive in basically all non-straightforward cases. |
This comment has been minimized.
|
Yes, that code compiles. Because for any lifetime |
This comment has been minimized.
reem
commented
Nov 30, 2015
|
Ah, I see, that's a nice generalization. |
mcasper commentedNov 30, 2015
Deriving
Queriablefor structs with explicit lifetimes blows up with the error message:for the struct
And trying to implement the trait by hand got tricky, I got stuck on what
$row_typeevaluates to.