use core::fmt;
use alloc::boxed::Box;
pub type IOError = embedded_io::ErrorKind;
pub type IOResult<T = ()> = Result<T, IOError>;
pub type BoxWrite = Box<dyn Write>;
pub trait Write: Send + Sync {
fn write(&mut self, buf: &[u8]) -> IOResult<usize>;
fn flush(&mut self) -> IOResult;
fn write_all(&mut self, mut buf: &[u8]) -> IOResult {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => panic!("write() returned Ok(0)"),
Ok(n) => buf = &buf[n..],
Err(e) => return Err(e),
}
}
Ok(())
}
}
impl fmt::Write for dyn Write {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
}
}