feat(service): Implement Clone/Copy on ServiceFn and MakeServiceFn (#2104)
This commit is contained in:
committed by
Sean McArthur
parent
0eaf304644
commit
a5720fab4c
@@ -15,7 +15,6 @@ pub trait MakeConnection<Target>: self::sealed::Sealed<(Target,)> {
|
|||||||
type Future: Future<Output = Result<Self::Connection, Self::Error>>;
|
type Future: Future<Output = Result<Self::Connection, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
|
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
|
||||||
|
|
||||||
fn make_connection(&mut self, target: Target) -> Self::Future;
|
fn make_connection(&mut self, target: Target) -> Self::Future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +143,8 @@ where
|
|||||||
MakeServiceFn { f }
|
MakeServiceFn { f }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not exported from crate as this will likely be replaced with `impl Service`.
|
/// `MakeService` returned from [`make_service_fn`]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct MakeServiceFn<F> {
|
pub struct MakeServiceFn<F> {
|
||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not exported from crate as this will likely be replaced with `impl Service`.
|
/// Service returned by [`service_fn`]
|
||||||
pub struct ServiceFn<F, R> {
|
pub struct ServiceFn<F, R> {
|
||||||
f: F,
|
f: F,
|
||||||
_req: PhantomData<fn(R)>,
|
_req: PhantomData<fn(R)>,
|
||||||
@@ -68,3 +68,17 @@ impl<F, R> fmt::Debug for ServiceFn<F, R> {
|
|||||||
f.debug_struct("impl Service").finish()
|
f.debug_struct("impl Service").finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<F, R> Clone for ServiceFn<F, R>
|
||||||
|
where
|
||||||
|
F: Clone,
|
||||||
|
{
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
ServiceFn {
|
||||||
|
f: self.f.clone(),
|
||||||
|
_req: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F, R> Copy for ServiceFn<F, R> where F: Copy {}
|
||||||
|
|||||||
Reference in New Issue
Block a user