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 #1919

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions sqlx-core/src/pool/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::pool::inner::PoolInner;
use crate::pool::Pool;
use futures_core::future::BoxFuture;
use std::fmt::{self, Debug, Formatter};
use std::sync::Arc;
use std::time::{Duration, Instant};

/// Configuration options for [`Pool`][super::Pool].
Expand Down Expand Up @@ -40,18 +41,19 @@ use std::time::{Duration, Instant};
/// parameter everywhere, and `Box` is in the prelude so it doesn't need to be manually imported,
/// so having the closure return `Pin<Box<dyn Future>` directly is the path of least resistance from
/// the perspectives of both API designer and consumer.
#[derive(Clone)]
pub struct PoolOptions<DB: Database> {
pub(crate) test_before_acquire: bool,
pub(crate) after_connect: Option<
Box<
Arc<
dyn Fn(&mut DB::Connection, PoolConnectionMetadata) -> BoxFuture<'_, Result<(), Error>>
+ 'static
+ Send
+ Sync,
>,
>,
pub(crate) before_acquire: Option<
Box<
Arc<
dyn Fn(
&mut DB::Connection,
PoolConnectionMetadata,
Expand All @@ -62,7 +64,7 @@ pub struct PoolOptions<DB: Database> {
>,
>,
pub(crate) after_release: Option<
Box<
Arc<
dyn Fn(
&mut DB::Connection,
PoolConnectionMetadata,
Expand Down Expand Up @@ -268,7 +270,7 @@ impl<DB: Database> PoolOptions<DB> {
/// .await?;
///
/// Ok(())
/// }))
/// }))
/// .connect("postgres:// …").await?;
/// # Ok(())
/// # }
Expand All @@ -284,7 +286,7 @@ impl<DB: Database> PoolOptions<DB> {
+ Send
+ Sync,
{
self.after_connect = Some(Box::new(callback));
self.after_connect = Some(Arc::new(callback));
self
}

Expand Down Expand Up @@ -337,7 +339,7 @@ impl<DB: Database> PoolOptions<DB> {
+ Send
+ Sync,
{
self.before_acquire = Some(Box::new(callback));
self.before_acquire = Some(Arc::new(callback));
self
}

Expand Down Expand Up @@ -394,7 +396,7 @@ impl<DB: Database> PoolOptions<DB> {
+ Send
+ Sync,
{
self.after_release = Some(Box::new(callback));
self.after_release = Some(Arc::new(callback));
self
}

Expand Down