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
use std::rc::Rc;
use std::time::Duration;
use crate::sink::MqttSink;
pub struct Session<St>(Rc<SessionInner<St>>);
struct SessionInner<St> {
st: St,
sink: MqttSink,
timeout: Duration,
in_flight: usize,
}
impl<St> Clone for Session<St> {
fn clone(&self) -> Self {
Session(self.0.clone())
}
}
impl<St> Session<St> {
pub(crate) fn new(st: St, sink: MqttSink, timeout: Duration, in_flight: usize) -> Self {
Session(Rc::new(SessionInner {
st,
sink,
timeout,
in_flight,
}))
}
pub fn sink(&self) -> &MqttSink {
&self.0.sink
}
pub fn state(&self) -> &St {
&self.0.st
}
pub(super) fn params(&self) -> (Duration, usize) {
let inner = self.0.as_ref();
(inner.timeout, inner.in_flight)
}
}