Skip to content

Commit afc8be6

Browse files
committed
Add serial::Write implementation
1 parent 281ebd3 commit afc8be6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/serial_impl.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Implementation of [`Serial`](https://docs.rs/embedded-hal/0.2.1/embedded_hal/serial/index.html)
22
3-
use hal::serial::Read;
3+
use hal::serial::{Read, Write};
44
use nb;
55
use serial;
66

@@ -25,6 +25,25 @@ impl Read<u8> for Serial {
2525
}
2626
}
2727

28+
impl Write<u8> for Serial {
29+
type Error = serial::Error;
30+
31+
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
32+
use std::io::Write;
33+
self.0
34+
.write(&[word])
35+
.map_err(|err| nb::Error::Other(Self::Error::from(err)))?;
36+
Ok(())
37+
}
38+
39+
fn flush(&mut self) -> nb::Result<(), Self::Error> {
40+
use std::io::Write;
41+
self.0
42+
.flush()
43+
.map_err(|err| nb::Error::Other(Self::Error::from(err)))
44+
}
45+
}
46+
2847
#[cfg(test)]
2948
mod test {
3049
use super::*;

0 commit comments

Comments
 (0)