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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use async_trait::async_trait;
use bytes::Bytes;
use deadpool::managed;
use crate::client::{CoturnTelnetConnection, CoturnTelnetError};
pub type Pool = managed::Pool<CoturnTelnetConnection, CoturnTelnetError>;
pub type Error = managed::PoolError<CoturnTelnetError>;
pub type Connection =
managed::Object<CoturnTelnetConnection, CoturnTelnetError>;
type RecycleResult = managed::RecycleResult<CoturnTelnetError>;
#[derive(Debug)]
pub struct Manager {
addr: (String, u16),
pass: Bytes,
}
impl Manager {
#[inline]
pub fn new<S, P>(host: S, port: u16, pass: P) -> Self
where
S: Into<String>,
P: Into<Bytes>,
{
Self {
addr: (host.into(), port),
pass: pass.into(),
}
}
}
#[async_trait]
impl managed::Manager<CoturnTelnetConnection, CoturnTelnetError> for Manager {
#[inline]
async fn create(
&self,
) -> Result<CoturnTelnetConnection, CoturnTelnetError> {
Ok(CoturnTelnetConnection::connect(
(self.addr.0.as_str(), self.addr.1),
self.pass.clone(),
)
.await?)
}
#[inline]
async fn recycle(
&self,
conn: &mut CoturnTelnetConnection,
) -> RecycleResult {
Ok(conn.ping().await?)
}
}