-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement Clone
for PoolOptions
manually (#2548)
#2553
Conversation
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
Clone
for PoolOptions
manually (#2548)
@alilleybrinker can you run |
Sure! I've pushed a new commit with |
sqlx-core/src/pool/options.rs
Outdated
fn clone(&self) -> Self { | ||
PoolOptions { | ||
test_before_acquire: self.test_before_acquire, | ||
after_connect: self.after_connect.as_ref().map(Arc::clone), |
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.
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()
@alilleybrinker did you see my comment? |
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. |
@abonander Fixed! |
Trying to derive
Clone
automatically forPoolOptions
results in errors whenclone
is actually called. This is because the derive incorrectly determines thatClone
is not derivable due to the lack ofClone
implementation on theDB: 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 theConnection
associated type on the type parameter'sDatabase
trait impl).Manually implementing
Clone
side-steps this issue and insures the type is always actually cloneable.For reference: #2548