Skip to main content

Slot

Struct Slot 

Source
pub struct Slot<T: Copy> { /* private fields */ }
Expand description

A value that can be loaded and stored without locking.

Loads and a store can run concurrently. There may be up to Self::MAX_READERS_COUNT concurrent loads but only single concurrent store allowed. You can think of slot as of SPMC atomic varible but for non-atomic types.

Implemented using a triple-buffer.

Implementations§

Source§

impl<T: Copy> Slot<T>

Source

pub const MAX_READERS_COUNT: usize = State::MAX_READERS_COUNT

Source

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

Source

pub fn load(&self) -> T

On success returns stored value.

  • If there is no concurrent load takes place then the most recent value is returned
  • If there are concurring loads then the same value is returned by all of them.
Source

pub fn store(&self, value: T) -> Result<(), SlotStoreError>

Trait Implementations§

Source§

impl<T: Copy + Debug> Debug for Slot<T>

Source§

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

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

impl<T: Copy + Default> Default for Slot<T>

Source§

fn default() -> Self

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

impl<T: Copy + Send> Send for Slot<T>

Source§

impl<T: Copy + Send> Sync for Slot<T>

Auto Trait Implementations§

§

impl<T> !Freeze for Slot<T>

§

impl<T> !RefUnwindSafe for Slot<T>

§

impl<T> Unpin for Slot<T>
where T: Unpin,

§

impl<T> UnwindSafe for Slot<T>
where T: 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<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.