pub struct PinCell<T: ?Sized> { /* private fields */ }
Expand description
A mutable memory location with dynamically checked borrow rules
Unlike RefCell
, this type only allows pinned mutable access to the
inner value, enabling a “pin-safe” version of interior mutability.
See the standard library documentation for more information.
Implementations
sourceimpl<T: ?Sized> PinCell<T>
impl<T: ?Sized> PinCell<T>
sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref
exits scope. Multiple
immutable borrows can be taken out at the same time (both pinned and
unpinned).
sourcepub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned Ref
exits scope. Multiple
immutable borrows can be taken out at the same time (both pinned and
unpinned).
This is the non-panicking variant of borrow
.
sourcepub fn borrow_mut<'a>(self: Pin<&'a Self>) -> PinMut<'a, T>
pub fn borrow_mut<'a>(self: Pin<&'a Self>) -> PinMut<'a, T>
Mutably borrows the wrapped value, preserving its pinnedness.
The borrow lasts until the returned PinMut
or all PinMut
s derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
sourcepub fn try_borrow_mut<'a>(
self: Pin<&'a Self>
) -> Result<PinMut<'a, T>, BorrowMutError>
pub fn try_borrow_mut<'a>(
self: Pin<&'a Self>
) -> Result<PinMut<'a, T>, BorrowMutError>
Mutably borrows the wrapped value, preserving its pinnedness, returning an error if the value is currently borrowed.
The borrow lasts until the returned PinMut
or all PinMut
s derived
from it exit scope. The value cannot be borrowed while this borrow is
active.
This is the non-panicking variant of borrow_mut
.
sourcepub fn borrow_pin<'a>(self: Pin<&'a Self>) -> PinRef<'a, T>
pub fn borrow_pin<'a>(self: Pin<&'a Self>) -> PinRef<'a, T>
Immutably borrows the wrapped value, preserving its pinnedness.
The borrow lasts until the returned PinRef
exits scope. Multiple
immutable borrows can be taken out at the same time (both pinned and
unpinned).
sourcepub fn try_borrow_pin<'a>(
self: Pin<&'a Self>
) -> Result<PinRef<'a, T>, BorrowError>
pub fn try_borrow_pin<'a>(
self: Pin<&'a Self>
) -> Result<PinRef<'a, T>, BorrowError>
Immutably borrows the wrapped value, preserving its pinnedness, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned PinRef
exits scope. Multiple
immutable borrows can be taken out at the same time (both pinned and
unpinned).
This is the non-panicking variant of borrow_pin
.
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
This call borrows PinCell
mutably (at compile-time) so there is no
need for dynamic checks.
However be cautious: this method expects self to be mutable, which is
generally not the case when using a PinCell
. Take a look at the
borrow_mut
method instead if self isn’t mutable.
Also, please be aware that this method is only for special
circumstances and is usually not what you want. In case of doubt, use
borrow_mut
instead.
Trait Implementations
sourceimpl<T: PartialEq + ?Sized> PartialEq<PinCell<T>> for PinCell<T>
impl<T: PartialEq + ?Sized> PartialEq<PinCell<T>> for PinCell<T>
sourceimpl<T: PartialOrd + ?Sized> PartialOrd<PinCell<T>> for PinCell<T>
impl<T: PartialOrd + ?Sized> PartialOrd<PinCell<T>> for PinCell<T>
sourcefn partial_cmp(&self, other: &PinCell<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &PinCell<T>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more