pub enum IoError {
EndOfFile,
NoFreeSpace,
Unknown,
WriteProhibited,
ReadProhibited
}
pub type Result<T> = core::result::Result<T,IoError>;
pub trait Read {
fn read(&mut self, _buf: &mut [u8]) -> avr_oxide::io::Result<usize>;
}
pub trait Write {
fn write(&mut self, buf: &[u8]) -> avr_oxide::io::Result<usize>;
fn flush(&mut self) -> avr_oxide::io::Result<()>;
}
#[cfg(not(target_arch="avr"))]
impl Read for std::io::Stdin {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
match std::io::Read::read(self, buf) {
Ok(b) => Ok(b),
Err(_e) => Err(IoError::Unknown)
}
}
}
#[cfg(not(target_arch="avr"))]
impl Write for std::io::Stdout {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
match std::io::Write::write(self, buf) {
Ok(b) => Ok(b),
Err(_e) => Err(IoError::Unknown)
}
}
fn flush(&mut self) -> Result<()> {
std::io::Write::flush(self);
Ok(())
}
}
#[cfg(not(target_arch="avr"))]
impl Write for std::io::Stderr {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
match std::io::Write::write(self, buf) {
Ok(b) => Ok(b),
Err(_e) => Err(IoError::Unknown)
}
}
fn flush(&mut self) -> Result<()> {
std::io::Write::flush(self);
Ok(())
}
}