Struct bufferring::storage::Slot

source ·
#[repr(transparent)]
pub struct Slot<T> { /* private fields */ }
Expand description

A slot for storing a single ring buffer item.

According to the Storage API, individual slots in the data buffer can be initialized or uninitialized, and some may be borrowed mutably. This is a convienience wrapper which provides both of these properties, combining both MaybeUninit and UnsafeCell with a useful API.

Slots do not require initialization, like MaybeUninit; they are valid even if constructed uninitialized. This allows them to be created in arrays and the like without any work.

Implementations§

source§

impl<T> Slot<T>

source

pub fn uninit() -> Self

Create a new, uninitialized slot.

source

pub fn new(item: T) -> Self

Create a new slot containing the given item.

source

pub unsafe fn get(self) -> T

Extract the contained item by value.

This is an unsafe function; it can only be called if the slot is known to be initialized.

source

pub unsafe fn get_ref(&self) -> &T

Get a shared reference to the item.

This is an unsafe function; it can only be called if the slot is known to be initialized, and if no unique references to the item (e.g. due to get_int_mut()) already exist.

source

pub unsafe fn get_mut(&mut self) -> &mut T

Get a unique reference to the item.

This is an unsafe function; it can only be called if the slot is known to be initialized.

source

pub unsafe fn get_int_mut(&self) -> &mut T

Get an interior-mutable reference to the item.

This is an unsafe function; it can only be called if the slot is known to be initialized, and if no unique references to the item (e.g. due to get_int_mut()) already exist.

source

pub unsafe fn take(&mut self) -> T

Take the item, leaving uninitialized data behind.

This is an unsafe function; it can only be called if the slot is known to be initialized.

source

pub unsafe fn drop_in_place(&mut self)

Drop the item contained in this slot.

This is an unsafe function; it can only be called if the slot is known to be initialized.

Trait Implementations§

source§

impl<T: Sync> Sync for Slot<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Slot<T>

§

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

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.