Skip to content

Commit

Permalink
Rename serial trait methods try_*
Browse files Browse the repository at this point in the history
  • Loading branch information
eldruin committed Mar 12, 2020
1 parent b5ad852 commit da83c02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/blocking/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ pub mod write {

fn try_bwrite_all(&mut self, buffer: &[Word]) -> Result<(), Self::Error> {
for word in buffer {
block!(self.write(word.clone()))?;
block!(self.try_write(word.clone()))?;
}

Ok(())
}

fn try_bflush(&mut self) -> Result<(), Self::Error> {
block!(self.flush())?;
block!(self.try_flush())?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ where
let _ = s
.as_bytes()
.into_iter()
.map(|c| block!(self.write(Word::from(*c))))
.map(|c| block!(self.try_write(Word::from(*c))))
.last();
Ok(())
}
Expand Down
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
//! type Error;
//!
//! /// Reads a single byte
//! fn read(&mut self) -> nb::Result<u8, Self::Error>;
//! fn try_read(&mut self) -> nb::Result<u8, Self::Error>;
//!
//! /// Writes a single byte
//! fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error>;
//! fn try_write(&mut self, byte: u8) -> nb::Result<(), Self::Error>;
//! }
//! ```
//!
Expand Down Expand Up @@ -150,7 +150,7 @@
//! impl hal::serial::Read<u8> for Serial<USART1> {
//! type Error = Error;
//!
//! fn read(&mut self) -> nb::Result<u8, Error> {
//! fn try_read(&mut self) -> nb::Result<u8, Error> {
//! // read the status register
//! let isr = self.usart.isr.read();
//!
Expand All @@ -172,13 +172,13 @@
//! impl hal::serial::Write<u8> for Serial<USART1> {
//! type Error = Error;
//!
//! fn write(&mut self, byte: u8) -> nb::Result<(), Error> {
//! // Similar to the `read` implementation
//! fn try_write(&mut self, byte: u8) -> nb::Result<(), Error> {
//! // Similar to the `try_read` implementation
//! # Ok(())
//! }
//!
//! fn flush(&mut self) -> nb::Result<(), Error> {
//! // Similar to the `read` implementation
//! fn try_flush(&mut self) -> nb::Result<(), Error> {
//! // Similar to the `try_read` implementation
//! # Ok(())
//! }
//! }
Expand Down Expand Up @@ -281,7 +281,7 @@
//! {
//! let mut serial = Some(serial);
//! future::poll_fn(move || {
//! let byte = try_nb!(serial.as_mut().unwrap().read());
//! let byte = try_nb!(serial.as_mut().unwrap().try_read());
//!
//! Ok(Async::Ready((serial.take().unwrap(), byte)))
//! })
Expand All @@ -296,7 +296,7 @@
//! {
//! let mut serial = Some(serial);
//! future::poll_fn(move || {
//! try_nb!(serial.as_mut().unwrap().write(byte));
//! try_nb!(serial.as_mut().unwrap().try_write(byte));
//!
//! Ok(Async::Ready(serial.take().unwrap()))
//! })
Expand Down Expand Up @@ -361,12 +361,12 @@
//! # pub struct Serial1;
//! # impl ::hal::serial::Read<u8> for Serial1 {
//! # type Error = Infallible;
//! # fn read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn try_read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
//! # }
//! # impl ::hal::serial::Write<u8> for Serial1 {
//! # type Error = Infallible;
//! # fn flush(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn try_flush(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn try_write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # }
//! #
//! # pub struct Led;
Expand Down Expand Up @@ -492,7 +492,7 @@
//! S: hal::serial::Write<u8>
//! {
//! for &byte in buffer {
//! block!(serial.write(byte))?;
//! block!(serial.try_write(byte))?;
//! }
//!
//! Ok(())
Expand Down Expand Up @@ -528,7 +528,7 @@
//! timer.try_start(timeout).map_err(Error::TimedOut)?;
//!
//! loop {
//! match serial.read() {
//! match serial.try_read() {
//! // raise error
//! Err(nb::Error::Other(e)) => return Err(Error::Serial(e)),
//! Err(nb::Error::WouldBlock) => {
Expand Down Expand Up @@ -608,7 +608,7 @@
//! {
//! loop {
//! if let Some(byte) = cb.peek() {
//! match serial.write(*byte) {
//! match serial.try_write(*byte) {
//! Err(nb::Error::Other(_)) => unreachable!(),
//! Err(nb::Error::WouldBlock) => return,
//! Ok(()) => {}, // keep flushing data
Expand Down Expand Up @@ -670,8 +670,8 @@
//! # struct Serial1;
//! # impl ::hal::serial::Write<u8> for Serial1 {
//! # type Error = Infallible;
//! # fn write(&mut self, _: u8) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn flush(&mut self) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn try_write(&mut self, _: u8) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # fn try_flush(&mut self) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
//! # }
//! # struct CircularBuffer;
//! # impl CircularBuffer {
Expand Down
6 changes: 3 additions & 3 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait Read<Word> {
type Error;

/// Reads a single word from the serial interface
fn read(&mut self) -> nb::Result<Word, Self::Error>;
fn try_read(&mut self) -> nb::Result<Word, Self::Error>;
}

/// Write half of a serial interface
Expand All @@ -20,8 +20,8 @@ pub trait Write<Word> {
type Error;

/// Writes a single word to the serial interface
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>;
fn try_write(&mut self, word: Word) -> nb::Result<(), Self::Error>;

/// Ensures that none of the previously written words are still buffered
fn flush(&mut self) -> nb::Result<(), Self::Error>;
fn try_flush(&mut self) -> nb::Result<(), Self::Error>;
}

0 comments on commit da83c02

Please sign in to comment.