sparrow-kata-full/apps/system/components/DebugConsole/kata-io/src/lib.rs
Matt Harvey fd2bebb81f Replaces processmanager with a one-app CAmkES assembly for the entire Kata OS
This also adds a skeleton for the DebugConsole CLI taking IO from a UART
via some Rust wrapper functions, also defined in this change
(kata-uart-client).

Change-Id: I56856c14992010483da58c45f6550c0a4c9987b0
GitOrigin-RevId: e1b2d65ed3a7f627a9f7377caa407151fc943864
2022-10-06 17:54:23 +00:00

36 lines
891 B
Rust

#![no_std]
pub struct Error;
/// Interface for the CLI to consume bytes.
pub trait Read {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>;
}
/// Interface for the CLI to emit bytes.
pub trait Write {
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>;
}
/// Adapter for writing core::fmt formatted strings.
impl core::fmt::Write for dyn Write + '_ {
/// Writes the bytes of a &str to the underlying writer.
fn write_str(&mut self, s: &str) -> core::fmt::Result {
match self.write(s.as_bytes()) {
Ok(_) => Ok(()),
Err(_) => Err(core::fmt::Error),
}
}
}
impl dyn Read + '_ {
pub fn get_u8(&mut self) -> Result<u8, Error> {
let mut buf: [u8; 1] = [0u8];
let n_read = self.read(&mut buf)?;
match n_read {
1usize => Ok(buf[0]),
_ => Err(Error),
}
}
}