Struct embassy_sync::pipe::Pipe
source · [−]Expand description
A bounded pipe for communicating between asynchronous tasks with backpressure.
The pipe will buffer up to the provided number of messages. Once the
buffer is full, attempts to write
new messages will wait until a message is
read from the pipe.
All data written will become available in the same order as it was written.
Implementations
sourceimpl<M, const N: usize> Pipe<M, N>where
M: RawMutex,
impl<M, const N: usize> Pipe<M, N>where
M: RawMutex,
sourcepub const fn new() -> Self
pub const fn new() -> Self
Establish a new bounded pipe. For example, to create one with a NoopMutex:
use embassy_sync::pipe::Pipe;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
// Declare a bounded pipe, with a buffer of 256 bytes.
let mut pipe = Pipe::<NoopRawMutex, 256>::new();
sourcepub fn write<'a>(&'a self, buf: &'a [u8]) -> WriteFuture<'a, M, N>ⓘNotable traits for WriteFuture<'p, M, N>impl<'p, M, const N: usize> Future for WriteFuture<'p, M, N>where
M: RawMutex, type Output = usize;
pub fn write<'a>(&'a self, buf: &'a [u8]) -> WriteFuture<'a, M, N>ⓘNotable traits for WriteFuture<'p, M, N>impl<'p, M, const N: usize> Future for WriteFuture<'p, M, N>where
M: RawMutex, type Output = usize;
M: RawMutex, type Output = usize;
Write a value, waiting until there is capacity.
Writeing completes when the value has been pushed to the pipe’s queue. This doesn’t mean the value has been read yet.
sourcepub fn read<'a>(&'a self, buf: &'a mut [u8]) -> ReadFuture<'a, M, N>ⓘNotable traits for ReadFuture<'p, M, N>impl<'p, M, const N: usize> Future for ReadFuture<'p, M, N>where
M: RawMutex, type Output = usize;
pub fn read<'a>(&'a self, buf: &'a mut [u8]) -> ReadFuture<'a, M, N>ⓘNotable traits for ReadFuture<'p, M, N>impl<'p, M, const N: usize> Future for ReadFuture<'p, M, N>where
M: RawMutex, type Output = usize;
M: RawMutex, type Output = usize;
Receive the next value.
If there are no messages in the pipe’s buffer, this method will wait until a message is written.
sourcepub fn try_read(&self, buf: &mut [u8]) -> Result<usize, TryReadError>
pub fn try_read(&self, buf: &mut [u8]) -> Result<usize, TryReadError>
Attempt to immediately read a message.
This method will either read a message from the pipe immediately or return an error if the pipe is empty.
sourcepub fn free_capacity(&self) -> usize
pub fn free_capacity(&self) -> usize
Free byte capacity.
This is equivalent to capacity() - len()
Trait Implementations
sourceimpl<M: RawMutex, const N: usize> Io for &Pipe<M, N>
impl<M: RawMutex, const N: usize> Io for &Pipe<M, N>
type Error = Infallible
type Error = Infallible
sourceimpl<M: RawMutex, const N: usize> Io for Pipe<M, N>
impl<M: RawMutex, const N: usize> Io for Pipe<M, N>
type Error = Infallible
type Error = Infallible
sourceimpl<M: RawMutex, const N: usize> Read for &Pipe<M, N>
impl<M: RawMutex, const N: usize> Read for &Pipe<M, N>
type ReadFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <&Pipe<M, N> as Io>::Error>> + 'a
type ReadFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <&Pipe<M, N> as Io>::Error>> + 'a
read
.sourcefn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>
sourcefn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>> + 'a
fn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>> + 'a
buf
.sourceimpl<M: RawMutex, const N: usize> Read for Pipe<M, N>
impl<M: RawMutex, const N: usize> Read for Pipe<M, N>
type ReadFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <Pipe<M, N> as Io>::Error>> + 'a
type ReadFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <Pipe<M, N> as Io>::Error>> + 'a
read
.sourcefn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>
sourcefn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>> + 'a
fn read_exact(
&'a mut self,
buf: &'a mut [u8]
) -> impl Future<Output = Result<(), ReadExactError<Self::Error>>> + 'a
buf
.sourceimpl<M: RawMutex, const N: usize> Write for &Pipe<M, N>
impl<M: RawMutex, const N: usize> Write for &Pipe<M, N>
type WriteFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <&Pipe<M, N> as Io>::Error>> + 'a
type WriteFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <&Pipe<M, N> as Io>::Error>> + 'a
write
.sourcefn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>
type FlushFuture<'a>
where
Self: 'a = impl Future<Output = Result<(), <&Pipe<M, N> as Io>::Error>> + 'a
type FlushFuture<'a>
where
Self: 'a = impl Future<Output = Result<(), <&Pipe<M, N> as Io>::Error>> + 'a
flush
.sourcefn flush<'a>(&'a mut self) -> Self::FlushFuture<'a>
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a>
sourceimpl<M: RawMutex, const N: usize> Write for Pipe<M, N>
impl<M: RawMutex, const N: usize> Write for Pipe<M, N>
type WriteFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <Pipe<M, N> as Io>::Error>> + 'a
type WriteFuture<'a>
where
Self: 'a = impl Future<Output = Result<usize, <Pipe<M, N> as Io>::Error>> + 'a
write
.sourcefn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>
type FlushFuture<'a>
where
Self: 'a = impl Future<Output = Result<(), <Pipe<M, N> as Io>::Error>> + 'a
type FlushFuture<'a>
where
Self: 'a = impl Future<Output = Result<(), <Pipe<M, N> as Io>::Error>> + 'a
flush
.