mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
Implement Clone for PoolOptions (#1919)
To not break the API we need to use an Arc instead of a Box for the callback functions. Alternatively we could require all the function to be Clone, but that would be a breaking change.
This commit is contained in:
parent
3d4861fd7c
commit
39eadd6d6d
@ -5,6 +5,7 @@ use crate::pool::inner::PoolInner;
|
|||||||
use crate::pool::Pool;
|
use crate::pool::Pool;
|
||||||
use futures_core::future::BoxFuture;
|
use futures_core::future::BoxFuture;
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
/// Configuration options for [`Pool`][super::Pool].
|
/// Configuration options for [`Pool`][super::Pool].
|
||||||
@ -40,10 +41,11 @@ use std::time::{Duration, Instant};
|
|||||||
/// parameter everywhere, and `Box` is in the prelude so it doesn't need to be manually imported,
|
/// 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
|
/// 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.
|
/// the perspectives of both API designer and consumer.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct PoolOptions<DB: Database> {
|
pub struct PoolOptions<DB: Database> {
|
||||||
pub(crate) test_before_acquire: bool,
|
pub(crate) test_before_acquire: bool,
|
||||||
pub(crate) after_connect: Option<
|
pub(crate) after_connect: Option<
|
||||||
Box<
|
Arc<
|
||||||
dyn Fn(&mut DB::Connection, PoolConnectionMetadata) -> BoxFuture<'_, Result<(), Error>>
|
dyn Fn(&mut DB::Connection, PoolConnectionMetadata) -> BoxFuture<'_, Result<(), Error>>
|
||||||
+ 'static
|
+ 'static
|
||||||
+ Send
|
+ Send
|
||||||
@ -51,7 +53,7 @@ pub struct PoolOptions<DB: Database> {
|
|||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
pub(crate) before_acquire: Option<
|
pub(crate) before_acquire: Option<
|
||||||
Box<
|
Arc<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
&mut DB::Connection,
|
&mut DB::Connection,
|
||||||
PoolConnectionMetadata,
|
PoolConnectionMetadata,
|
||||||
@ -62,7 +64,7 @@ pub struct PoolOptions<DB: Database> {
|
|||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
pub(crate) after_release: Option<
|
pub(crate) after_release: Option<
|
||||||
Box<
|
Arc<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
&mut DB::Connection,
|
&mut DB::Connection,
|
||||||
PoolConnectionMetadata,
|
PoolConnectionMetadata,
|
||||||
@ -284,7 +286,7 @@ impl<DB: Database> PoolOptions<DB> {
|
|||||||
+ Send
|
+ Send
|
||||||
+ Sync,
|
+ Sync,
|
||||||
{
|
{
|
||||||
self.after_connect = Some(Box::new(callback));
|
self.after_connect = Some(Arc::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +339,7 @@ impl<DB: Database> PoolOptions<DB> {
|
|||||||
+ Send
|
+ Send
|
||||||
+ Sync,
|
+ Sync,
|
||||||
{
|
{
|
||||||
self.before_acquire = Some(Box::new(callback));
|
self.before_acquire = Some(Arc::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +396,7 @@ impl<DB: Database> PoolOptions<DB> {
|
|||||||
+ Send
|
+ Send
|
||||||
+ Sync,
|
+ Sync,
|
||||||
{
|
{
|
||||||
self.after_release = Some(Box::new(callback));
|
self.after_release = Some(Arc::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user