Stream

Struct Stream 

Source
pub struct Stream<const N: usize> { /* private fields */ }
Expand description

Byte-oriented stream buffer with compile-time buffer size.

Wraps ove_stream_t for passing variable-length byte data between threads or between ISR and thread contexts. N is the buffer size in bytes.

Implementations§

Source§

impl<const N: usize> Stream<N>

Source

pub fn new(trigger: usize) -> Result<Self>

Create a stream via heap allocation (only in heap mode).

Source

pub fn send(&self, data: &[u8], timeout_ms: u32) -> Result<usize>

Send bytes into the stream, blocking up to timeout_ms if the buffer is full.

Returns the number of bytes actually sent, which may be less than data.len() if the stream fills before the timeout.

§Errors

Returns Error::Timeout if no bytes could be sent within timeout_ms.

Source

pub fn receive(&self, buf: &mut [u8], timeout_ms: u32) -> Result<usize>

Receive bytes from the stream into buf, blocking up to timeout_ms.

Returns the number of bytes actually received. Blocks until at least the trigger byte count (set at creation time) is available, or timeout_ms expires.

§Errors

Returns Error::Timeout if no bytes could be received within timeout_ms.

Source

pub fn send_from_isr(&self, data: &[u8]) -> Result<usize>

Send bytes from an ISR context (non-blocking, returns immediately).

Returns the number of bytes sent; may be less than data.len() if the buffer fills.

§Errors

Returns an error if the stream is full.

Source

pub fn receive_from_isr(&self, buf: &mut [u8]) -> Result<usize>

Receive bytes from an ISR context (non-blocking, returns immediately).

Returns the number of bytes received; may be zero if no data is available.

§Errors

Returns an error if the stream is empty.

Source

pub fn reset(&self) -> Result<()>

Reset the stream, discarding all currently buffered data.

§Errors

Returns an error if the underlying RTOS call fails.

Source

pub fn bytes_available(&self) -> usize

Return the number of bytes currently available for reading.

Trait Implementations§

Source§

impl<const N: usize> Drop for Stream<N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const N: usize> Send for Stream<N>

Source§

impl<const N: usize> Sync for Stream<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Stream<N>

§

impl<const N: usize> RefUnwindSafe for Stream<N>

§

impl<const N: usize> Unpin for Stream<N>

§

impl<const N: usize> UnwindSafe for Stream<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, 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.