Skip to content

Commit

Permalink
Add serial::Write implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Dec 24, 2018
1 parent 030cf0b commit deccbc1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/serial_impl.rs
Expand Up @@ -2,7 +2,7 @@


use nb;
use ::hal::serial::Read;
use ::hal::serial::{Read, Write};
use ::serial;

/// Newtype around [`serial::SystemPort`] that implements the `embedded-hal` traits
Expand All @@ -24,6 +24,23 @@ impl Read<u8> for Serial {
}
}

impl Write<u8> for Serial {
type Error = serial::Error;

fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
use std::io::Write;
self.0.write(&[word])
.map_err(|err| nb::Error::Other(Self::Error::from(err)))?;
Ok(())
}

fn flush(&mut self) -> nb::Result<(), Self::Error> {
use std::io::Write;
self.0.flush()
.map_err(|err| nb::Error::Other(Self::Error::from(err)))
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit deccbc1

Please sign in to comment.