Struct PinCell

Source
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§

Source§

impl<T> PinCell<T>

Source

pub const fn new(value: T) -> PinCell<T>

Creates a new PinCell containing value.

Source§

impl<T: ?Sized> PinCell<T>

Source

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).

Source

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.

Source

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 PinMuts derived from it exit scope. The value cannot be borrowed while this borrow is active.

Source

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 PinMuts derived from it exit scope. The value cannot be borrowed while this borrow is active.

This is the non-panicking variant of borrow_mut.

Source

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).

Source

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.

Source

pub fn as_ptr(&self) -> *mut T

Returns a raw pointer to the underlying data in this cell.

Source

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§

Source§

impl<T: Clone + ?Sized> Clone for PinCell<T>

Source§

fn clone(&self) -> PinCell<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + ?Sized> Debug for PinCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + ?Sized> Default for PinCell<T>

Source§

fn default() -> PinCell<T>

Returns the “default value” for a type. Read more
Source§

impl<T> From<RefCell<T>> for PinCell<T>

Source§

fn from(cell: RefCell<T>) -> PinCell<T>

Converts to this type from the input type.
Source§

impl<T> From<T> for PinCell<T>

Source§

fn from(value: T) -> PinCell<T>

Converts to this type from the input type.
Source§

impl<T> Into<RefCell<T>> for PinCell<T>

Source§

fn into(self) -> RefCell<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: Ord + ?Sized> Ord for PinCell<T>

Source§

fn cmp(&self, other: &PinCell<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + ?Sized> PartialEq for PinCell<T>

Source§

fn eq(&self, other: &PinCell<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + ?Sized> PartialOrd for PinCell<T>

Source§

fn partial_cmp(&self, other: &PinCell<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq + ?Sized> Eq for PinCell<T>

Source§

impl<T: ?Sized> StructuralPartialEq for PinCell<T>

Auto Trait Implementations§

§

impl<T> !Freeze for PinCell<T>

§

impl<T> !RefUnwindSafe for PinCell<T>

§

impl<T> Send for PinCell<T>
where T: Send + ?Sized,

§

impl<T> !Sync for PinCell<T>

§

impl<T> Unpin for PinCell<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for PinCell<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.