Struct DecoderReader

Source
pub struct DecoderReader<B, R>
where B: Buffer, R: ByteSource,
{ /* private fields */ }
Expand description

Decode transmissions read from a byte source

Implementations§

Source§

impl<B, R> DecoderReader<B, R>
where B: Buffer, R: ByteSource,

Source

pub fn new(reader: R) -> Self

Create a new decoder wrapping the provided reader.

Source

pub fn read(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>

Reads and decodes a transmission

On success, returns the decoded transmission (Ok(bytes)). Otherwise, returns errors (which can either be decoding errors or errors returned from the byte source).

When reading from a finite data source (such as a file containing a certain number of transmissions), it’s easier to use next instead, which handles EOFs correctly.

See also read_nb, which provides a convenient API for non-blocking byte sources.

Source

pub fn next(&mut self) -> Option<Result<&[u8], ReadDecodedError<R::ReadError>>>

Tries to read and decode a transmission

On success, returns the decoded transmission (Some(Ok(bytes))). Returns None if the reader returns EOF immediately. Otherwise, returns errors (which can either be decoding errors or errors returned from the byte source).

When reading from a data source that will provide data infinitely (such as from a serial port), it’s easier to use read instead.

See also next_nb, which provides a convenient API for non-blocking byte sources.

Source

pub fn read_nb(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>

Available on crate feature nb only.

Reads and decodes a transmission (non-blocking)

Same as read except that it returns nb::Result. If reading from the byte source indicates that data isn’t available yet, this method returns Err(nb::Error::WouldBlock).

Using nb::Result allows this method to be awaited using the nb::block! macro.

This function is available only if sml-rs is built with the "nb" or "embedded_hal" features.

Source

pub fn next_nb( &mut self, ) -> Result<Option<&[u8]>, ReadDecodedError<R::ReadError>>

Available on crate feature nb only.

Tries to read and decode a transmission (non-blocking)

Same as next except that it returns nb::Result. If reading from the byte source indicates that data isn’t available yet, this method returns Err(nb::Error::WouldBlock).

Using nb::Result allows this method to be awaited using the nb::block! macro.

This function is available only if sml-rs is built with the "nb" or "embedded_hal" features.

Auto Trait Implementations§

§

impl<B, R> Freeze for DecoderReader<B, R>
where R: Freeze, B: Freeze,

§

impl<B, R> RefUnwindSafe for DecoderReader<B, R>

§

impl<B, R> Send for DecoderReader<B, R>
where R: Send, B: Send,

§

impl<B, R> Sync for DecoderReader<B, R>
where R: Sync, B: Sync,

§

impl<B, R> Unpin for DecoderReader<B, R>
where R: Unpin, B: Unpin,

§

impl<B, R> UnwindSafe for DecoderReader<B, R>
where R: UnwindSafe, B: UnwindSafe,

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.