1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-12-18 17:53:12 +01:00
actix-net/actix-ioframe/src/cell.rs

36 lines
653 B
Rust
Raw Normal View History

2019-06-26 11:19:40 +02:00
//! Custom cell impl
use std::cell::UnsafeCell;
use std::fmt;
use std::rc::Rc;
pub(crate) struct Cell<T> {
inner: Rc<UnsafeCell<T>>,
}
impl<T> Clone for Cell<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<T: fmt::Debug> fmt::Debug for Cell<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
}
impl<T> Cell<T> {
pub fn new(inner: T) -> Self {
Self {
inner: Rc::new(UnsafeCell::new(inner)),
}
}
2019-07-17 07:16:38 +02:00
pub(crate) unsafe fn get_mut(&mut self) -> &mut T {
&mut *self.inner.as_ref().get()
2019-06-26 11:19:40 +02:00
}
}