e310x-hal 0.12.0

HAL for the E310x family of microcontrollers.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Stdout
use core::fmt::{Error, Result, Write};

/// Stdout implements the core::fmt::Write trait for embedded_io::Write implementations.
pub struct Stdout<'p, T: 'p>(pub &'p mut T);

impl<T: embedded_io::Write> Write for Stdout<'_, T> {
    fn write_str(&mut self, s: &str) -> Result {
        for byte in s.as_bytes() {
            if *byte == b'\n' {
                self.0.write(b"\r").map_err(|_| Error)?;
            }
            self.0.write(&[*byte]).map_err(|_| Error)?;
        }
        Ok(())
    }
}