Skip to content

Commit 77a6dad

Browse files
committed
Improved serial write_str implementation to properly handle errors
Signed-off-by: Daniel Egger <[email protected]>
1 parent d0f4500 commit 77a6dad

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515

1616
- Updated to stm32-rs v0.6.0 - @HarkonenBade
1717
- Updated the ADC code to use variants added in stm32-rs v0.6.0 - @HarkonenBade
18+
- Improved serial `write_str` implementation
1819

1920
## [v0.12.0] - 2019-01-13
2021

src/serial.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,10 @@ where
518518
Tx<USART>: embedded_hal::serial::Write<u8>,
519519
{
520520
fn write_str(&mut self, s: &str) -> Result {
521-
use nb::block;
522-
523-
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
524-
Ok(())
521+
s.as_bytes()
522+
.iter()
523+
.try_for_each(|c| nb::block!(self.write(*c)))
524+
.map_err(|_| core::fmt::Error)
525525
}
526526
}
527527

@@ -531,10 +531,10 @@ where
531531
TXPIN: TxPin<USART>,
532532
{
533533
fn write_str(&mut self, s: &str) -> Result {
534-
use nb::block;
535-
536-
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
537-
Ok(())
534+
s.as_bytes()
535+
.iter()
536+
.try_for_each(|c| nb::block!(self.write(*c)))
537+
.map_err(|_| core::fmt::Error)
538538
}
539539
}
540540

0 commit comments

Comments
 (0)