Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Clone/Copy on ServiceFn and MakeServiceFn #2104

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}