1pub use core::fmt::Write;
3use nb::block;
4
5pub struct Stdout<'p, T>(pub &'p mut T);
8
9impl<'p, T> Write for Stdout<'p, T>
10 where
11 T: embedded_hal::serial::Write<u8>,
12{
13 fn write_str(&mut self, s: &str) -> core::fmt::Result {
14 for byte in s.as_bytes() {
15 if *byte == b'\n' {
16 let res = block!(self.0.write(b'\r'));
17
18 if res.is_err() {
19 return Err(core::fmt::Error);
20 }
21 }
22
23 let res = block!(self.0.write(*byte));
24
25 if res.is_err() {
26 return Err(core::fmt::Error);
27 }
28 }
29 Ok(())
30 }
31}