use std::cell::{Ref, RefCell, RefMut}; use std::rc::Rc; /// Connection state /// /// Connection state is an arbitrary data attached to the each incoming message. #[derive(Debug)] pub struct State(Rc>); impl State { pub(crate) fn new(st: T) -> Self { State(Rc::new(RefCell::new(st))) } #[inline] pub fn get_ref(&self) -> Ref { self.0.borrow() } #[inline] pub fn get_mut(&mut self) -> RefMut { self.0.borrow_mut() } } impl Clone for State { fn clone(&self) -> Self { State(self.0.clone()) } }