Skip to content

Commit

Permalink
Merge #111
Browse files Browse the repository at this point in the history
111: impl Write for serial::Write r=ryankurte a=thenewwazoo

Shamelessly pilfered from [@therealprof's code](https://github.com/therealprof/stm32f042-hal/blob/master/src/serial.rs). Still needs Changelog entry, but I thought this was a good idea after a discussion on IRC.

Co-authored-by: Brandon Matthews <[email protected]>
  • Loading branch information
bors[bot] and thenewwazoo committed Feb 23, 2019
2 parents f2a36d1 + d14d6cd commit dd92c3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Implementation of `core::fmt::Write` for the HAL's `serial::Write`.
//!
//! TODO write example of usage
use core::fmt::{Result, Write};

impl<Word, Error> Write for ::serial::Write<Word, Error=Error>
where
Word: From<u8>,
{
fn write_str(&mut self, s: &str) -> Result {
let _ = s.as_bytes()
.into_iter()
.map(|c| block!(self.write(Word::from(*c))))
.last();
Ok(())
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ extern crate void;
pub mod adc;
pub mod blocking;
pub mod digital;
pub mod fmt;
pub mod prelude;
pub mod serial;
pub mod spi;
Expand Down

0 comments on commit dd92c3a

Please sign in to comment.