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:
Matt Harvey 2021-09-14 16:04:34 -07:00 committed by Sam Leffler
parent d4a369a6c3
commit c0df9a3b95

View File

@ -2,14 +2,16 @@
pub struct Error;
pub type Result<T> = core::result::Result<T, Error>;
/// Interface for the CLI to consume bytes.
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.
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.
@ -24,7 +26,7 @@ impl core::fmt::Write for dyn Write + '_ {
}
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 n_read = self.read(&mut buf)?;
match n_read {