Skip to content

Commit

Permalink
feat(service): Implement Clone/Copy on ServiceFn and MakeServiceFn (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes authored and seanmonstar committed Jan 8, 2020
1 parent 0eaf304 commit a5720fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/service/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub trait MakeConnection<Target>: self::sealed::Sealed<(Target,)> {
type Future: Future<Output = Result<Self::Connection, Self::Error>>;

fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;

fn make_connection(&mut self, target: Target) -> Self::Future;
}

Expand Down Expand Up @@ -144,7 +143,8 @@ where
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> {
f: F,
}
Expand Down
16 changes: 15 additions & 1 deletion src/service/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
f: F,
_req: PhantomData<fn(R)>,
Expand Down Expand Up @@ -68,3 +68,17 @@ impl<F, R> fmt::Debug for ServiceFn<F, R> {
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 {}

0 comments on commit a5720fa

Please sign in to comment.