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§
Sourcefn read(&self, buf: &mut [u8]) -> Result<usize>
fn read(&self, buf: &mut [u8]) -> Result<usize>
Reads UART receive data into buf, returning the number of bytes read.
This function is blocking.
Sourcefn read_timeout(&self, buf: &mut [u8], timeout: Duration) -> Result<usize>
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(_).
Sourcefn logged(self) -> Logged<Self>where
Self: Sized,
fn logged(self) -> Logged<Self>where
Self: Sized,
Return a wrapper that logs all outputs while reading.
Sourcefn try_wait_for_line<P: MatchPattern>(
&self,
pattern: P,
timeout: Duration,
) -> Result<Option<P::MatchResult>>
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.
Sourcefn wait_for_line<P: MatchPattern>(
&self,
pattern: P,
timeout: Duration,
) -> Result<P::MatchResult>
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 valueRegex: regex captures are returned.(T, E), whereTandEare one of the above: match two patterns at once. If the first matches,Okis returned, otherwiseErris. Note that when this is used, you would haveanyhow::Result<Result<TMatch, EMatch>>from this function, where theErr(_)is I/O error or timeout, andOk(Err(_))is the match forE.
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.