pub struct Pipe<M, const N: usize>where
    M: RawMutex,
{ /* private fields */ }
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

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();

Get a writer for this pipe.

Get a reader for this pipe.

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.

Attempt to immediately write a message.

This method differs from write by returning immediately if the pipe’s buffer is full, instead of waiting.

Errors

If the pipe capacity has been reached, i.e., the pipe has n buffered values where n is the argument passed to Pipe, then an error is returned.

Receive the next value.

If there are no messages in the pipe’s buffer, this method will wait until a message is written.

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.

Clear the data in the pipe’s buffer.

Return whether the pipe is full (no free space in the buffer)

Return whether the pipe is empty (no data buffered)

Total byte capacity.

This is the same as the N generic param.

Used byte capacity.

Free byte capacity.

This is equivalent to capacity() - len()

Trait Implementations

Error type of all the IO operations on this type.
Error type of all the IO operations on this type.
Future returned by read.
Pull some bytes from this source into the specified buffer, returning how many bytes were read.
Read the exact number of bytes required to fill buf.
Future returned by read.
Pull some bytes from this source into the specified buffer, returning how many bytes were read.
Read the exact number of bytes required to fill buf.
Future returned by write.
Write a buffer into this writer, returning how many bytes were written.
Future returned by flush.
Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Write an entire buffer into this writer.
Future returned by write.
Write a buffer into this writer, returning how many bytes were written.
Future returned by flush.
Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Write an entire buffer into this writer.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.