Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Derive Generic FromSql/ToSql#931

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sfackler merged 2 commits intorust-postgres:masterfrommatt-duch:derive-generic
Sep 7, 2022

Conversation

matt-duch
Copy link
Contributor

Allows for derivation of FromSql and ToSql for generic types. Borrowed types are allowed for ToSql, but not meaningful to support for FromSql (so not supported). (also noted in#570)

Would you be interested in this change? A test was added. Happy to iterate.

AngusWaller and schneiderfelipe reacted with thumbs up emoji
Comment on lines 245 to 247
structInventoryItem<T:FromSqlOwned,U>
where
U:FromSqlOwned,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are these bounds actually required?

Copy link
ContributorAuthor

@matt-duchmatt-duchAug 9, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FromSqlOwned is required for#[derive(FromSql)] which is needed to run the test. Or were you asking about the derivedDebug andPartialEq?

Edit: I also put the bounds in the two different positions to test that bounds and where clauses work as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Derive logic should normally insert those bounds on the generated impls as necessary - you don't needwhere T: Clone at the struct definition when using#[derive(Clone)] for example.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just to make sure I understand the change request, the idea is add a FromSql<'a> bound on any generic type in the FromSql derive logic?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yep.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So I started implementing this, and ran into an ambiguity (where this differs fromClone, which is in the rust prelude). I need to create a path to the FromSql and ToSql traits, however it could be one of a few options:

  1. From the postgres_derive crate (postgres_derive::FromSql<'a, T>, but I think most uses will not import this crate directly)
  2. From the postgres_types crate (postgres_types::FromSql<'a, T>)
  3. Some other crate that re-exports or renames those types (no way to use a path from a crate name)
  4. Assume that it'sused somewhere (FromSql<'a, T>)
    Any suggestions on which assumption to use?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Here's how the path is already produced in the existing logic:https://github.com/sfackler/rust-postgres/blob/master/postgres-derive/src/fromsql.rs#L90

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for pointing that out. Based on that, looks like it was option (2). Branch is updated, and tests pass locally.

@matt-duch
Copy link
ContributorAuthor

Updated to fix the two issues (lint and failing test).

@AngusWaller
Copy link

AngusWaller commentedSep 1, 2022
edited
Loading

Hope this gets in soon, derive is breaking on any struct thats borrowed/lifetimes

@sfackler
Copy link
Collaborator

Sorry for the delay - LGTM other than the clippy failures!

AngusWaller reacted with heart emoji

@matt-duch
Copy link
ContributorAuthor

@sfackler Sorry about that. Fixed, clippy runs locally, and pushed.

@sfacklersfackler merged commit1e944c4 intorust-postgres:masterSep 7, 2022
@sfackler
Copy link
Collaborator

Thanks! I will cut a release tomorrow.

@matt-duchmatt-duch deleted the derive-generic branchSeptember 7, 2022 14:05
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sfacklersfacklersfackler left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@matt-duch@AngusWaller@sfackler

[8]ページ先頭

©2009-2025 Movatter.jp