Skip to main content

Writer

Struct Writer 

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

Writer for an mpsc Storable type.

Multiple writers can coexist for the same type, each writing to their own value. A single exclusive Reader consumes values from all writers.

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

§Usage

Each writer is assigned a unique place to store a value. Writer::write stores a value in that place and notifies the reader. Like single_writer::Writer, Writer::write is async and waits to give the Reader a chance to read the value.

§Examples

// Writing values.
#[veecle_os_runtime::actor]
async fn command_sender<const N: usize>(mut writer: Writer<'_, Command, N>) -> veecle_os_runtime::Never {
    let mut counter = 0;
    loop {
        // After the first write, this call will yield to the executor before allowing the next write.
        writer.write(Command(counter)).await;
        counter += 1;
    }
}

Fields§

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

Implementations§

§

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

pub async fn write(&mut self, item: <T as Storable>::DataType)

Available on crate feature data-support-can only.

Writes a new value and notifies the reader.

pub async fn ready(&mut self)

Available on crate feature data-support-can only.

Waits for the writer to be ready to perform a write operation.

After awaiting this method, the next call to Writer::write() is guaranteed to resolve immediately.

Trait Implementations§

§

impl<'a, T, const N: usize> Debug for Writer<'a, T, N>
where T: Debug + 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 Writer<'a, T, N>
where T: Storable + 'static,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T, const N: usize> !UnwindSafe for Writer<'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.