Skip to content
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

Implement Clone for PoolOptions manually (#2548) #2553

Merged
merged 3 commits into from
Jul 9, 2023
Merged

Implement Clone for PoolOptions manually (#2548) #2553

merged 3 commits into from
Jul 9, 2023

Conversation

alilleybrinker
Copy link
Contributor

Trying to derive Clone automatically for PoolOptions results in errors when clone is actually called. This is because the derive incorrectly determines that Clone is not derivable due to the lack of Clone implementation on the DB: Database type parameter, even though no value of that type is actually stored in a to-be-cloned position (in fact, it's only used for the Connection associated type on the type parameter's Database trait impl).

Manually implementing Clone side-steps this issue and insures the type is always actually cloneable.

For reference: #2548

Trying to derive `Clone` automatically for `PoolOptions` results
in errors when `clone` is actually called. This is because the
derive incorrectly determines that `Clone` is _not_ derivable
due to the lack of `Clone` implementation on the `DB: Database`
type parameter, even though no value of that type is actually
stored in a to-be-cloned position (in fact, it's only used for
the `Connection` associated type on the type parameter's
`Database` trait impl).

Manually implementing `Clone` side-steps this issue and insures
the type is always actually cloneable.

For reference: #2548
@alilleybrinker alilleybrinker changed the title Implement Clone for PoolOptions manually (#2548) Implement Clone for PoolOptions manually (#2548) Jun 18, 2023
@abonander
Copy link
Collaborator

@alilleybrinker can you run cargo fmt?

@alilleybrinker
Copy link
Contributor Author

Sure! I've pushed a new commit with cargo fmt having been run.

fn clone(&self) -> Self {
PoolOptions {
test_before_acquire: self.test_before_acquire,
after_connect: self.after_connect.as_ref().map(Arc::clone),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Option actually implements Clone which forwards to the inner type: https://doc.rust-lang.org/stable/std/option/enum.Option.html#impl-Clone-for-Option%3CT%3E

So you can change all of these to just .clone()

@abonander
Copy link
Collaborator

@alilleybrinker did you see my comment?

@alilleybrinker
Copy link
Contributor Author

Yes, I don't think I'll be able to get to this today, but I should be able to do it in the next couple of days.

@alilleybrinker
Copy link
Contributor Author

@abonander Fixed!

@abonander abonander merged commit f06c4c2 into launchbadge:main Jul 9, 2023
@alilleybrinker alilleybrinker deleted the bugfix/cloneable_pooloptions branch July 10, 2023 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants