mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 01:11:07 +01:00
export cell
This commit is contained in:
parent
a16ad6b2cd
commit
5937a06ebe
16
src/cell.rs
16
src/cell.rs
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user