1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-02-05 05:42:19 +00: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::fmt;
use std::rc::Rc; use std::rc::Rc;
pub(crate) struct Cell<T> { #[doc(hidden)]
pub struct Cell<T> {
#[cfg(feature = "cell")] #[cfg(feature = "cell")]
inner: Rc<UnsafeCell<T>>, inner: Rc<UnsafeCell<T>>,
#[cfg(not(feature = "cell"))] #[cfg(not(feature = "cell"))]
@ -30,33 +31,34 @@ impl<T: fmt::Debug> fmt::Debug for Cell<T> {
#[cfg(feature = "cell")] #[cfg(feature = "cell")]
impl<T> Cell<T> { impl<T> Cell<T> {
pub(crate) fn new(inner: T) -> Self { pub fn new(inner: T) -> Self {
Self { Self {
inner: Rc::new(UnsafeCell::new(inner)), inner: Rc::new(UnsafeCell::new(inner)),
} }
} }
pub(crate) fn borrow(&self) -> &T { pub fn borrow(&self) -> &T {
unsafe { &*self.inner.as_ref().get() } 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() } unsafe { &mut *self.inner.as_ref().get() }
} }
} }
#[cfg(not(feature = "cell"))] #[cfg(not(feature = "cell"))]
impl<T> Cell<T> { impl<T> Cell<T> {
pub(crate) fn new(inner: T) -> Self { pub fn new(inner: T) -> Self {
Self { Self {
inner: Rc::new(RefCell::new(inner)), inner: Rc::new(RefCell::new(inner)),
} }
} }
pub(crate) fn borrow(&self) -> Ref<T> { pub fn borrow(&self) -> Ref<T> {
self.inner.borrow() self.inner.borrow()
} }
pub(crate) fn borrow_mut(&self) -> RefMut<T> {
pub fn borrow_mut(&self) -> RefMut<T> {
self.inner.borrow_mut() self.inner.borrow_mut()
} }
} }

View file

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