Skip to content

Commit 7b19068

Browse files
authored
Merge pull request #101 from stm32-rs/infallible-instead-of-void
Use core::convert::Infallible instead of void::Void for USARTs
2 parents 0ff6b0c + ae29706 commit 7b19068

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/serial.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
use core::{
6262
fmt::{Result, Write},
6363
ops::Deref,
64+
convert::Infallible,
6465
};
6566

6667
use embedded_hal::prelude::*;
@@ -451,7 +452,7 @@ impl<USART> embedded_hal::serial::Write<u8> for Tx<USART>
451452
where
452453
USART: Deref<Target = SerialRegisterBlock>,
453454
{
454-
type Error = void::Void;
455+
type Error = Infallible;
455456

456457
/// Ensures that none of the previously written words are still buffered
457458
fn flush(&mut self) -> nb::Result<(), Self::Error> {
@@ -470,7 +471,7 @@ where
470471
USART: Deref<Target = SerialRegisterBlock>,
471472
TXPIN: TxPin<USART>,
472473
{
473-
type Error = void::Void;
474+
type Error = Infallible;
474475

475476
/// Ensures that none of the previously written words are still buffered
476477
fn flush(&mut self) -> nb::Result<(), Self::Error> {
@@ -538,7 +539,7 @@ where
538539
}
539540

540541
/// Ensures that none of the previously written words are still buffered
541-
fn flush(usart: *const SerialRegisterBlock) -> nb::Result<(), void::Void> {
542+
fn flush(usart: *const SerialRegisterBlock) -> nb::Result<(), Infallible> {
542543
// NOTE(unsafe) atomic read with no side effects
543544
let isr = unsafe { (*usart).isr.read() };
544545

@@ -550,8 +551,8 @@ fn flush(usart: *const SerialRegisterBlock) -> nb::Result<(), void::Void> {
550551
}
551552

552553
/// Tries to write a byte to the UART
553-
/// Fails if the transmit buffer is full
554-
fn write(usart: *const SerialRegisterBlock, byte: u8) -> nb::Result<(), void::Void> {
554+
/// Returns `Err(WouldBlock)` if the transmit buffer is full
555+
fn write(usart: *const SerialRegisterBlock, byte: u8) -> nb::Result<(), Infallible> {
555556
// NOTE(unsafe) atomic read with no side effects
556557
let isr = unsafe { (*usart).isr.read() };
557558

0 commit comments

Comments
 (0)