Skip to main content

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 create( storage: &'static StreamStorage<N>, trigger: usize, ) -> Result<Self>

Mode-agnostic constructor (see crate::Mutex::create). Heap mode ignores storage; zero-heap mode backs the stream with its storage and embedded byte buffer.

Source

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

Send bytes, blocking indefinitely if the buffer is full. Returns the number of bytes actually sent (may be < data.len()).

Source

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

Non-blocking send. Returns the number of bytes actually sent.

§Errors

Returns Error::WouldBlock if the buffer is full and no bytes could be written.

Source

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

Send up to d. Returns the number of bytes actually sent.

Source

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

Send by the given deadline. Returns the number of bytes actually sent.

Source

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

Receive bytes, blocking indefinitely. Returns the number of bytes actually read (may be < buf.len() — blocks until at least the trigger byte count is available).

Source

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

Non-blocking receive. Returns the number of bytes read.

§Errors

Returns Error::WouldBlock if no bytes are available.

Source

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

Receive up to d.

Source

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

Receive by the given deadline.

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.

Source

pub unsafe fn set_notify( &self, cb: Option<unsafe extern "C" fn(*mut c_void)>, user_data: *mut c_void, ) -> Result<()>

Register a notify callback fired after every successful send. Wraps the C-level ove_stream_set_notify.

§Safety
  • user_data must remain valid for as long as the callback may fire — i.e. until either the stream is destroyed or set_notify(None, ...) clears the registration.
  • cb may be invoked from any context the producer uses, including ISR. Its body must therefore be non-blocking and ISR-safe.

Higher-level users should reach for the async wrappers in ove::async_runtime instead of using this directly — they hide the lifetime and ISR-safety constraints behind a safe API.

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> ErrorType for Stream<N>

Source§

type Error = Error

Error type of all the IO operations on this type.
Source§

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

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

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

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
Source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. 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> UnsafeUnpin 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.