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: usizeImplementations§
§impl<T, const N: usize> Writer<'_, T, N>where
T: Storable + 'static,
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.
pub async fn write(&mut self, item: <T as Storable>::DataType)
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.
pub async fn ready(&mut self)
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> 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more