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>
impl<const N: usize> Stream<N>
Sourcepub fn new(trigger: usize) -> Result<Self>
pub fn new(trigger: usize) -> Result<Self>
Create a stream via heap allocation (only in heap mode).
Sourcepub fn create(
storage: &'static StreamStorage<N>,
trigger: usize,
) -> Result<Self>
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.
Sourcepub fn send(&self, data: &[u8]) -> Result<usize>
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()).
Sourcepub fn try_send(&self, data: &[u8]) -> Result<usize>
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.
Sourcepub fn try_send_for(&self, data: &[u8], d: Duration) -> Result<usize>
pub fn try_send_for(&self, data: &[u8], d: Duration) -> Result<usize>
Send up to d. Returns the number of bytes actually sent.
Sourcepub fn try_send_until(&self, data: &[u8], deadline: Instant) -> Result<usize>
pub fn try_send_until(&self, data: &[u8], deadline: Instant) -> Result<usize>
Send by the given deadline. Returns the number of bytes actually sent.
Sourcepub fn recv(&self, buf: &mut [u8]) -> Result<usize>
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).
Sourcepub fn try_recv(&self, buf: &mut [u8]) -> Result<usize>
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.
Sourcepub fn try_recv_until(&self, buf: &mut [u8], deadline: Instant) -> Result<usize>
pub fn try_recv_until(&self, buf: &mut [u8], deadline: Instant) -> Result<usize>
Receive by the given deadline.
Sourcepub fn send_from_isr(&self, data: &[u8]) -> Result<usize>
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.
Sourcepub fn receive_from_isr(&self, buf: &mut [u8]) -> Result<usize>
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.
Sourcepub fn reset(&self) -> Result<()>
pub fn reset(&self) -> Result<()>
Reset the stream, discarding all currently buffered data.
§Errors
Returns an error if the underlying RTOS call fails.
Sourcepub fn bytes_available(&self) -> usize
pub fn bytes_available(&self) -> usize
Return the number of bytes currently available for reading.
Sourcepub unsafe fn set_notify(
&self,
cb: Option<unsafe extern "C" fn(*mut c_void)>,
user_data: *mut c_void,
) -> Result<()>
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_datamust remain valid for as long as the callback may fire — i.e. until either the stream is destroyed orset_notify(None, ...)clears the registration.cbmay 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> Read for Stream<N>
impl<const N: usize> Read for Stream<N>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read more