-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Adds support for zero-copy FromSql derive #1070
base: master
Are you sure you want to change the base?
Conversation
Similar in spirit and implementation to how `serde` supports borrowed deserialization lifetimes. Like `serde`, it uses `'de` as the lifetime of the trait (`FromoSql<'de>`) and it adds all borrowed liftimes as lifetime bounds on `'de`. Also like `serde` all top level references automatically have their lifetimes borrowed, but container types carrying references must explicity be borrowed with the `#[postgres(borrow)]` annotation.
fn build_generics(source: &Generics, borrowed_lifetimes: HashSet<Lifetime>) -> (Generics, Lifetime) { | ||
// This is the same parent lifetime name serde uses | ||
let lifetime = Lifetime::new("'de", Span::call_site()); | ||
// Sort lifetimes for deterministic code-gen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also preserve the declared order of lifetimes rather than going through a hashset and then sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I was over-optimizing on the extraction path to handle lifetime dedup. In the real-world though, a simple borrowed_lifetimes.contains(lifetime)
shouldn't ever be a problem. I made the changes to go through a vec instead of a hashset and preserve declaration order.
Can anyone w/ maintainer privileges please kick off the test workflow 🙏 |
Similar in spirit and implementation to how
serde
supports borrowed deserialization lifetimes. Likeserde
, it uses'de
as the lifetime of the trait (FromSql<'de>
) and it adds all borrowed liftimes as lifetime bounds on'de
.Also like
serde
all top level references automatically have their lifetimes borrowed, but container types carrying references must explicity be borrowed with the#[postgres(borrow)]
annotation.Follows up on: #574