1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 01:11:07 +01:00

export cell

This commit is contained in:
Nikolay Kim 2018-12-03 13:49:46 -08:00
parent a16ad6b2cd
commit 5937a06ebe
2 changed files with 11 additions and 8 deletions

View File

@ -7,7 +7,8 @@ use std::cell::{Ref, RefCell, RefMut};
use std::fmt;
use std::rc::Rc;
pub(crate) struct Cell<T> {
#[doc(hidden)]
pub struct Cell<T> {
#[cfg(feature = "cell")]
inner: Rc<UnsafeCell<T>>,
#[cfg(not(feature = "cell"))]
@ -30,33 +31,34 @@ impl<T: fmt::Debug> fmt::Debug for Cell<T> {
#[cfg(feature = "cell")]
impl<T> Cell<T> {
pub(crate) fn new(inner: T) -> Self {
pub fn new(inner: T) -> Self {
Self {
inner: Rc::new(UnsafeCell::new(inner)),
}
}
pub(crate) fn borrow(&self) -> &T {
pub fn borrow(&self) -> &T {
unsafe { &*self.inner.as_ref().get() }
}
pub(crate) fn borrow_mut(&self) -> &mut T {
pub fn borrow_mut(&self) -> &mut T {
unsafe { &mut *self.inner.as_ref().get() }
}
}
#[cfg(not(feature = "cell"))]
impl<T> Cell<T> {
pub(crate) fn new(inner: T) -> Self {
pub fn new(inner: T) -> Self {
Self {
inner: Rc::new(RefCell::new(inner)),
}
}
pub(crate) fn borrow(&self) -> Ref<T> {
pub fn borrow(&self) -> Ref<T> {
self.inner.borrow()
}
pub(crate) fn borrow_mut(&self) -> RefMut<T> {
pub fn borrow_mut(&self) -> RefMut<T> {
self.inner.borrow_mut()
}
}

View File

@ -55,7 +55,8 @@ extern crate webpki;
#[cfg(feature = "rust-tls")]
extern crate webpki_roots;
mod cell;
#[doc(hidden)]
pub mod cell;
pub mod cloneable;
pub mod codec;
pub mod connector;