Trait ConsoleExt

Source
pub trait ConsoleExt {
    // Required methods
    fn read(&self, buf: &mut [u8]) -> Result<usize>;
    fn read_timeout(&self, buf: &mut [u8], timeout: Duration) -> Result<usize>;
    fn logged(self) -> Logged<Self>
       where Self: Sized;
    fn try_wait_for_line<P: MatchPattern>(
        &self,
        pattern: P,
        timeout: Duration,
    ) -> Result<Option<P::MatchResult>>;
    fn wait_for_line<P: MatchPattern>(
        &self,
        pattern: P,
        timeout: Duration,
    ) -> Result<P::MatchResult>;
}
Expand description

Extension trait to [Uart] where useful methods are provided.

Required Methods§

Source

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

Reads UART receive data into buf, returning the number of bytes read. This function is blocking.

Source

fn read_timeout(&self, buf: &mut [u8], timeout: Duration) -> Result<usize>

Reads UART receive data into buf, returning the number of bytes read. The timeout may be used to specify a duration to wait for data. If timeout expires without any data arriving Ok(0) will be returned, never Err(_).

Source

fn logged(self) -> Logged<Self>
where Self: Sized,

Return a wrapper that logs all outputs while reading.

Source

fn try_wait_for_line<P: MatchPattern>( &self, pattern: P, timeout: Duration, ) -> Result<Option<P::MatchResult>>

Wait for a line that matches the specified pattern to appear.

The pattern matched is returned. If timeout occurs, None is returned.

Source

fn wait_for_line<P: MatchPattern>( &self, pattern: P, timeout: Duration, ) -> Result<P::MatchResult>

Wait for a line that matches the specified pattern to appear.

Types that can be used include:

  • str`` / u8`: literal matching is performed, no return value
  • Regex: regex captures are returned.
  • (T, E), where T and E are one of the above: match two patterns at once. If the first matches, Ok is returned, otherwise Err is. Note that when this is used, you would have anyhow::Result<Result<TMatch, EMatch>> from this function, where the Err(_) is I/O error or timeout, and Ok(Err(_)) is the match for E.

If you want to construct a static &Regex you can use regex! macro.

The pattern matched is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§