Skip to content

Commit a5720fa

Browse files
Marwesseanmonstar
authored andcommitted
feat(service): Implement Clone/Copy on ServiceFn and MakeServiceFn (#2104)
1 parent 0eaf304 commit a5720fa

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/service/make.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub trait MakeConnection<Target>: self::sealed::Sealed<(Target,)> {
1515
type Future: Future<Output = Result<Self::Connection, Self::Error>>;
1616

1717
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
18-
1918
fn make_connection(&mut self, target: Target) -> Self::Future;
2019
}
2120

@@ -144,7 +143,8 @@ where
144143
MakeServiceFn { f }
145144
}
146145

147-
// Not exported from crate as this will likely be replaced with `impl Service`.
146+
/// `MakeService` returned from [`make_service_fn`]
147+
#[derive(Clone, Copy)]
148148
pub struct MakeServiceFn<F> {
149149
f: F,
150150
}

src/service/util.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
}
3636
}
3737

38-
// Not exported from crate as this will likely be replaced with `impl Service`.
38+
/// Service returned by [`service_fn`]
3939
pub struct ServiceFn<F, R> {
4040
f: F,
4141
_req: PhantomData<fn(R)>,
@@ -68,3 +68,17 @@ impl<F, R> fmt::Debug for ServiceFn<F, R> {
6868
f.debug_struct("impl Service").finish()
6969
}
7070
}
71+
72+
impl<F, R> Clone for ServiceFn<F, R>
73+
where
74+
F: Clone,
75+
{
76+
fn clone(&self) -> Self {
77+
ServiceFn {
78+
f: self.f.clone(),
79+
_req: PhantomData,
80+
}
81+
}
82+
}
83+
84+
impl<F, R> Copy for ServiceFn<F, R> where F: Copy {}

0 commit comments

Comments
 (0)