Skip to main content

KCell

Struct KCell 

Source
pub struct KCell<T, Class> { /* private fields */ }
Expand description

A container cell that safe-guards data of type T using type-level lock class tracking.

KCell holds data that can only be safely accessed (read or written) by proving that the corresponding mutual exclusion lock of class Class is currently held by the current thread via a LockToken.

Implementations§

Source§

impl<T, Class> KCell<T, Class>

Source

pub const fn new(value: T) -> Self

Creates a new KCell containing the specified value.

Source

pub unsafe fn get<'b>(&self, _token: &'b LockToken<'_, Class>) -> &'b T

Access the guarded value immutably using a shared lock token.

§Safety

The caller must guarantee that:

  1. The provided LockToken belongs to the specific lock instance that guards this KCell (rather than a different lock of the same lock class Class).
  2. The lock is held continuously for the lifetime of the returned reference 'b.
Source

pub unsafe fn get_mut<'b>( &self, _token: &'b mut LockToken<'_, Class>, ) -> &'b mut T

Access the guarded value mutably using a mutable lock token.

§Safety

The caller must guarantee that:

  1. The provided LockToken belongs to the specific lock instance that guards this KCell (rather than a different lock of the same lock class Class).
  2. The lock is held continuously for the lifetime of the returned reference 'b.
Source

pub unsafe fn as_mut_ptr(&self, _token: &mut LockToken<'_, Class>) -> *mut T

Returns a mutable raw pointer to the guarded value.

§Safety

The caller must guarantee that the lock instance guarding this KCell is held continuously while dereferencing or accessing the returned raw pointer.

Source

pub fn get_inner_mut(&mut self) -> &mut T

Accesses the inner value mutably by bypassing the locking requirements using unique borrow ownership.

Source

pub fn into_inner(self) -> T

Unwraps the cell, returning the inner value.

Trait Implementations§

Source§

impl<T, Class> AsMut<T> for KCell<T, Class>

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, Class> Debug for KCell<T, Class>

Source§

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

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

impl<T: Default, Class> Default for KCell<T, Class>

Source§

fn default() -> Self

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

impl<T, Class> From<T> for KCell<T, Class>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T, Class, I, E> PinInit<KCell<T, Class>, E> for KCellInit<I, Class>
where I: PinInit<T, E>,

Source§

unsafe fn __pinned_init(self, slot: *mut KCell<T, Class>) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T: Send, Class> Send for KCell<T, Class>

Source§

impl<T: Send, Class> Sync for KCell<T, Class>

Auto Trait Implementations§

§

impl<T, Class> !Freeze for KCell<T, Class>

§

impl<T, Class> !RefUnwindSafe for KCell<T, Class>

§

impl<T, Class> Unpin for KCell<T, Class>
where T: Unpin, Class: Unpin,

§

impl<T, Class> UnsafeUnpin for KCell<T, Class>
where T: UnsafeUnpin,

§

impl<T, Class> UnwindSafe for KCell<T, Class>
where T: UnwindSafe, Class: UnwindSafe,

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> 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> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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.