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
mod app;
mod connect;
mod control;
mod dispatcher;
pub mod errors;
mod handshake;
mod link;
mod message;
pub mod sasl;
mod service;

pub use self::app::App;
pub use self::connect::{Connect, ConnectAck, ConnectOpened};
pub use self::control::{ControlFrame, ControlFrameKind};
pub use self::handshake::{handshake, Handshake};
pub use self::link::Link;
pub use self::message::{Message, Outcome};
pub use self::sasl::Sasl;
pub use self::service::Server;

use crate::cell::Cell;

pub struct State<St>(Cell<St>);

impl<St> State<St> {
    pub(crate) fn new(st: St) -> Self {
        State(Cell::new(st))
    }

    pub(crate) fn clone(&self) -> Self {
        State(self.0.clone())
    }

    pub fn get_ref(&self) -> &St {
        self.0.get_ref()
    }

    pub fn get_mut(&mut self) -> &mut St {
        self.0.get_mut()
    }
}

impl<St> std::ops::Deref for State<St> {
    type Target = St;

    fn deref(&self) -> &Self::Target {
        self.get_ref()
    }
}

impl<St> std::ops::DerefMut for State<St> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        self.get_mut()
    }
}