1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-08-31 22:06:59 +02:00

add custom framed dispatcher service

This commit is contained in:
Nikolay Kim
2019-06-26 15:19:40 +06:00
parent 07708c5e9a
commit 205cac82ce
13 changed files with 1008 additions and 0 deletions

39
actix-ioframe/src/cell.rs Normal file
View File

@@ -0,0 +1,39 @@
//! 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)),
}
}
pub fn get_ref(&self) -> &T {
unsafe { &*self.inner.as_ref().get() }
}
pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.inner.as_ref().get() }
}
}