1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::convert::Infallible;

use super::MakeService;

#[derive(Debug, Clone)]
pub struct CloneFactory<T> {
    svc: T,
}

impl<T> MakeService for CloneFactory<T>
where
    T: Clone,
{
    type Service = T;

    type Error = Infallible;

    #[inline]
    fn make_via_ref(&self, _old: Option<&Self::Service>) -> Result<Self::Service, Self::Error> {
        Ok(self.svc.clone())
    }
}

impl<T> From<T> for CloneFactory<T> {
    #[inline]
    fn from(svc: T) -> Self {
        CloneFactory { svc }
    }
}

impl<T> CloneFactory<T> {
    #[inline]
    pub const fn new(svc: T) -> Self {
        Self { svc }
    }

    #[inline]
    pub fn into_inner(self) -> T {
        self.svc
    }
}