Skip to main content

Reader

Struct Reader 

pub struct Reader<'a, T, const N: usize>
where T: Storable + 'static,
{ slot: Pin<&'a Slot<T, N>>, waiter: Waiter<'a>, }
Expand description

Exclusive reader for Storable types from an mpsc slot.

Reads values written by multiple Writers for the same type. Reading a value takes ownership from the slot, marking it as consumed.

The generic type T specifies the type of the value being read. The const generic N specifies the maximum number of writers.

§Usage

Reader::take_all_updated reads all available value via closure, waiting if no values are currently available.

Reader::take_all reads all available value via closure.

Reader::take_one returns one value if available.

§Examples

// Using `take_all` to process all available values.
#[veecle_os_runtime::actor]
async fn command_handler<const N: usize>(mut reader: Reader<'_, Command, N>) -> veecle_os_runtime::Never {
    loop {
        reader.wait_for_update().await;
        reader.take_all(|command| {
            // Process the command.
        });
    }
}

Fields§

§slot: Pin<&'a Slot<T, N>>§waiter: Waiter<'a>

Implementations§

§

impl<T, const N: usize> Reader<'_, T, N>
where T: Storable + 'static,

pub fn is_updated(&self) -> bool

Available on crate feature data-support-can only.

Returns true if an unseen value is available.

A value becomes “seen” after calling take_one, take_all, or similar read methods.

May return true after a reading method if more unseen values are available.

pub async fn wait_for_update(&mut self) -> &mut Reader<'_, T, N>

Available on crate feature data-support-can only.

Waits for unseen values to become available.

This future resolving does not imply that previous_value != new_value, just that a Writer has written a value of T since the last read operation.

Returns &mut Self to allow chaining method calls.

pub fn take_one(&mut self) -> Option<<T as Storable>::DataType>

Available on crate feature data-support-can only.

Takes the next available value, returns None if none are available.

pub fn take_all(&mut self, f: impl FnMut(<T as Storable>::DataType))

Available on crate feature data-support-can only.

Reads all available values.

Takes ownership of each value and passes it to f.

pub async fn take_all_updated( &mut self, f: impl FnMut(<T as Storable>::DataType), )

Available on crate feature data-support-can only.

Reads all available values, waiting if none are available.

Takes ownership of each value and passes it to f. When no values are available, waits for new writes and returns after reading at least one value.

Trait Implementations§

§

impl<T, const N: usize> Debug for Reader<'_, T, N>
where T: Storable + 'static,

§

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

Formats the value using the given formatter. Read more
§

impl<'a, T, const N: usize> StoreRequest<'a> for Reader<'a, T, N>
where T: Storable + 'static,

Auto Trait Implementations§

§

impl<'a, T, const N: usize> Freeze for Reader<'a, T, N>

§

impl<'a, T, const N: usize> !RefUnwindSafe for Reader<'a, T, N>

§

impl<'a, T, const N: usize> !Send for Reader<'a, T, N>

§

impl<'a, T, const N: usize> !Sync for Reader<'a, T, N>

§

impl<'a, T, const N: usize> Unpin for Reader<'a, T, N>

§

impl<'a, T, const N: usize> !UnwindSafe for Reader<'a, T, N>

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

Source§

type Output = T

Should always be Self
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.