1use std::convert::Infallible;
2
3use super::MakeService;
4
5#[derive(Debug, Clone)]
6pub struct CloneFactory<T> {
7 svc: T,
8}
9
10impl<T> MakeService for CloneFactory<T>
11where
12 T: Clone,
13{
14 type Service = T;
15
16 type Error = Infallible;
17
18 #[inline]
19 fn make_via_ref(&self, _old: Option<&Self::Service>) -> Result<Self::Service, Self::Error> {
20 Ok(self.svc.clone())
21 }
22}
23
24impl<T> From<T> for CloneFactory<T> {
25 #[inline]
26 fn from(svc: T) -> Self {
27 CloneFactory { svc }
28 }
29}
30
31impl<T> CloneFactory<T> {
32 #[inline]
33 pub const fn new(svc: T) -> Self {
34 Self { svc }
35 }
36
37 #[inline]
38 pub fn into_inner(self) -> T {
39 self.svc
40 }
41}