From dbafdc79a0edfe38ea4797dcf62ef67c7f56b267 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 22 Sep 2017 18:48:41 +0200 Subject: [PATCH] Address review comment --- src/lib.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1c4a00..30da51b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,7 +195,7 @@ //! //! /// A synchronized serial interface //! // NOTE This is a global singleton -//! pub struct Serial1(Mutex<..>); +//! pub struct Serial1; //! //! // NOTE private //! static USART1: Mutex<_> = Mutex::new(..); @@ -204,7 +204,7 @@ //! type Error = !; //! //! fn read(&self) -> Result> { -//! hal::serial::Read::read(&Serial1(USART1.lock())) +//! hal::serial::Read::read(&Serial(&*USART1.lock())) //! } //! } //! ``` @@ -269,36 +269,47 @@ //! /// `futures` version of `Timer.wait` //! /// //! /// This returns a future that must be polled to completion -//! fn wait(timer: T) -> impl Future +//! fn wait(timer: T) -> impl Future //! where //! T: hal::Timer, //! { -//! future::poll_fn(move || { -//! Ok(Async::Ready(try_nb!(timer.wait()))) +//! future::loop_fn(timer, |timer| { +//! match timer.wait() { +//! Ok(()) => Ok(Loop::Break(timer)), +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(timer)), +//! } //! }) //! } //! //! /// `futures` version of `Serial.read` //! /// //! /// This returns a future that must be polled to completion -//! fn read(serial: S) -> impl Future +//! fn read(serial: S) -> impl Future //! where //! S: hal::serial::Read, //! { -//! future::poll_fn(move || { -//! Ok(Async::Ready(try_nb!(serial.read()))) +//! future::loop_fn(serial, |mut serial| { +//! match serial.read() { +//! Ok(byte) => Ok(Loop::Break((serial, byte))), +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)), +//! Err(nb::Error::Other(error)) => Err(error), +//! } //! }) //! } //! //! /// `futures` version of `Serial.write` //! /// //! /// This returns a future that must be polled to completion -//! fn write(serial: S, byte: u8) -> impl Future +//! fn write(serial: S, byte: u8) -> impl Future //! where //! S: hal::serial::Write, //! { -//! future::poll_fn(move || { -//! Ok(Async::Ready(try_nb!(serial.write(byte)))) +//! future::loop_fn(serial, move |mut serial| { +//! match serial.write(byte) { +//! Ok(()) => Ok(Loop::Break(serial)), +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)), +//! Err(nb::Error::Other(error)) => Err(error), +//! } //! }) //! } //!