Browse Source

Improved serial write_str implementation to properly handle errors

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
trying.tmp
Daniel Egger 4 years ago
parent
commit
77a6dad00a
  1. 1
      CHANGELOG.md
  2. 16
      src/serial.rs

1
CHANGELOG.md

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Updated to stm32-rs v0.6.0 - @HarkonenBade
- Updated the ADC code to use variants added in stm32-rs v0.6.0 - @HarkonenBade
- Improved serial `write_str` implementation
## [v0.12.0] - 2019-01-13

16
src/serial.rs

@ -518,10 +518,10 @@ where
Tx<USART>: embedded_hal::serial::Write<u8>,
{
fn write_str(&mut self, s: &str) -> Result {
use nb::block;
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
Ok(())
s.as_bytes()
.iter()
.try_for_each(|c| nb::block!(self.write(*c)))
.map_err(|_| core::fmt::Error)
}
}
@ -531,10 +531,10 @@ where
TXPIN: TxPin<USART>,
{
fn write_str(&mut self, s: &str) -> Result {
use nb::block;
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
Ok(())
s.as_bytes()
.iter()
.try_for_each(|c| nb::block!(self.write(*c)))
.map_err(|_| core::fmt::Error)
}
}

Loading…
Cancel
Save