channel_server/common/
utils.rs1use std::{
2 cell::{Ref, RefCell, RefMut},
3 rc::Rc,
4};
5
6type RcCellType<T> = Rc<RefCell<T>>;
7
8pub struct RcCell<T> {
9 cell: RcCellType<T>,
10}
11
12impl<T> RcCell<T> {
13 pub fn new(data: T) -> Self {
14 Self {
15 cell: Rc::new(RefCell::new(data)),
16 }
17 }
18 pub fn as_mut(&self) -> RefMut<T> {
19 self.cell.as_ref().borrow_mut()
20 }
21
22 pub fn as_ref(&self) -> Ref<T> {
23 self.cell.as_ref().borrow()
24 }
25}
26
27impl<T> Clone for RcCell<T> {
28 fn clone(&self) -> Self {
29 Self {
30 cell: self.cell.clone(),
31 }
32 }
33}