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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::pool::{CheckOut, Dependencies};
use futures::Future;
use std::time::Instant;
pub enum Status {
Valid,
Invalid,
}
pub trait Manage: Sized {
type Resource: Send;
type Dependencies: Dependencies;
type CheckOut: From<CheckOut<Self>>;
type Error;
type CreateFuture: Future<Item = Self::Resource, Error = Self::Error>;
fn create(&self) -> Self::CreateFuture;
fn status(&self, resource: &Self::Resource) -> Status;
type RecycleFuture: Future<Item = Option<Self::Resource>, Error = Self::Error>;
fn recycle(&self, resource: Self::Resource) -> Self::RecycleFuture;
}
#[derive(Debug)]
pub struct Idle<R>
where
R: Send,
{
resource: R,
recycled_at: Instant,
}
impl<R> Idle<R>
where
R: Send,
{
pub fn new(resource: R, recycled_at: Instant) -> Self {
Self {
resource,
recycled_at,
}
}
pub fn into_resource(self) -> R {
self.resource
}
pub fn recycled_at(&self) -> Instant {
self.recycled_at
}
}