mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-08-25 00:08:33 +00:00
kata-io alias analogous to io::Result
Sometimes it is useful for kata-io to be API-compatible with std::io (e.g. porting a ZMODEM library). std::io has a similarly defined alias where E is its own error type. Change-Id: Idaf88fb1d41bcb984608d82a0ea222290c78f5c4 GitOrigin-RevId: 5738e6ac705b6fe3b48dd64891808cf50b75afb7
This commit is contained in:
parent
d4a369a6c3
commit
c0df9a3b95
@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
pub struct Error;
|
pub struct Error;
|
||||||
|
|
||||||
|
pub type Result<T> = core::result::Result<T, Error>;
|
||||||
|
|
||||||
/// Interface for the CLI to consume bytes.
|
/// Interface for the CLI to consume bytes.
|
||||||
pub trait Read {
|
pub trait Read {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>;
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interface for the CLI to emit bytes.
|
/// Interface for the CLI to emit bytes.
|
||||||
pub trait Write {
|
pub trait Write {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>;
|
fn write(&mut self, buf: &[u8]) -> Result<usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adapter for writing core::fmt formatted strings.
|
/// Adapter for writing core::fmt formatted strings.
|
||||||
@ -24,7 +26,7 @@ impl core::fmt::Write for dyn Write + '_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl dyn Read + '_ {
|
impl dyn Read + '_ {
|
||||||
pub fn get_u8(&mut self) -> Result<u8, Error> {
|
pub fn get_u8(&mut self) -> Result<u8> {
|
||||||
let mut buf: [u8; 1] = [0u8];
|
let mut buf: [u8; 1] = [0u8];
|
||||||
let n_read = self.read(&mut buf)?;
|
let n_read = self.read(&mut buf)?;
|
||||||
match n_read {
|
match n_read {
|
||||||
|
Loading…
Reference in New Issue
Block a user