Skip to content

Commit 9547648

Browse files
committed
Extract wrap_connector function for reuse
Signed-off-by: Piotr Jastrzebski <[email protected]>
1 parent a77f422 commit 9547648

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

libsql/src/database/builder.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,22 @@ cfg_remote! {
506506
}
507507

508508
cfg_replication_or_remote_or_sync! {
509+
fn wrap_connector<C>(connector: C) -> crate::util::ConnectorService
510+
where
511+
C: tower::Service<http::Uri> + Send + Clone + Sync + 'static,
512+
C::Response: crate::util::Socket,
513+
C::Future: Send + 'static,
514+
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
515+
{
516+
use tower::ServiceExt;
517+
518+
let svc = connector
519+
.map_err(|e| e.into())
520+
.map_response(|s| Box::new(s) as Box<dyn crate::util::Socket>);
521+
522+
crate::util::ConnectorService::new(svc)
523+
}
524+
509525
impl Remote {
510526
fn connector<C>(mut self, connector: C) -> Remote
511527
where
@@ -514,15 +530,7 @@ cfg_replication_or_remote_or_sync! {
514530
C::Future: Send + 'static,
515531
C::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
516532
{
517-
use tower::ServiceExt;
518-
519-
let svc = connector
520-
.map_err(|e| e.into())
521-
.map_response(|s| Box::new(s) as Box<dyn crate::util::Socket>);
522-
523-
let svc = crate::util::ConnectorService::new(svc);
524-
525-
self.connector = Some(svc);
533+
self.connector = Some(wrap_connector(connector));
526534
self
527535
}
528536

0 commit comments

Comments
 (0)