Skip to content

Commit dd92c3a

Browse files
Merge #111
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]>
2 parents f2a36d1 + d14d6cd commit dd92c3a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/fmt.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Implementation of `core::fmt::Write` for the HAL's `serial::Write`.
2+
//!
3+
//! TODO write example of usage
4+
use core::fmt::{Result, Write};
5+
6+
impl<Word, Error> Write for ::serial::Write<Word, Error=Error>
7+
where
8+
Word: From<u8>,
9+
{
10+
fn write_str(&mut self, s: &str) -> Result {
11+
let _ = s.as_bytes()
12+
.into_iter()
13+
.map(|c| block!(self.write(Word::from(*c))))
14+
.last();
15+
Ok(())
16+
}
17+
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ extern crate void;
693693
pub mod adc;
694694
pub mod blocking;
695695
pub mod digital;
696+
pub mod fmt;
696697
pub mod prelude;
697698
pub mod serial;
698699
pub mod spi;

0 commit comments

Comments
 (0)