Skip to content

Commit dbafdc7

Browse files
committed
Address review comment
1 parent 81abc9c commit dbafdc7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/lib.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
//!
196196
//! /// A synchronized serial interface
197197
//! // NOTE This is a global singleton
198-
//! pub struct Serial1(Mutex<..>);
198+
//! pub struct Serial1;
199199
//!
200200
//! // NOTE private
201201
//! static USART1: Mutex<_> = Mutex::new(..);
@@ -204,7 +204,7 @@
204204
//! type Error = !;
205205
//!
206206
//! fn read(&self) -> Result<u8, nb::Error<Self::Error>> {
207-
//! hal::serial::Read::read(&Serial1(USART1.lock()))
207+
//! hal::serial::Read::read(&Serial(&*USART1.lock()))
208208
//! }
209209
//! }
210210
//! ```
@@ -269,36 +269,47 @@
269269
//! /// `futures` version of `Timer.wait`
270270
//! ///
271271
//! /// This returns a future that must be polled to completion
272-
//! fn wait<T>(timer: T) -> impl Future<Item = (), Error = !>
272+
//! fn wait<T>(timer: T) -> impl Future<Item = T, Error = !>
273273
//! where
274274
//! T: hal::Timer,
275275
//! {
276-
//! future::poll_fn(move || {
277-
//! Ok(Async::Ready(try_nb!(timer.wait())))
276+
//! future::loop_fn(timer, |timer| {
277+
//! match timer.wait() {
278+
//! Ok(()) => Ok(Loop::Break(timer)),
279+
//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(timer)),
280+
//! }
278281
//! })
279282
//! }
280283
//!
281284
//! /// `futures` version of `Serial.read`
282285
//! ///
283286
//! /// This returns a future that must be polled to completion
284-
//! fn read<S>(serial: S) -> impl Future<Item = u8, Error = S::Error>
287+
//! fn read<S>(serial: S) -> impl Future<Item = (S, u8), Error = S::Error>
285288
//! where
286289
//! S: hal::serial::Read<u8>,
287290
//! {
288-
//! future::poll_fn(move || {
289-
//! Ok(Async::Ready(try_nb!(serial.read())))
291+
//! future::loop_fn(serial, |mut serial| {
292+
//! match serial.read() {
293+
//! Ok(byte) => Ok(Loop::Break((serial, byte))),
294+
//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)),
295+
//! Err(nb::Error::Other(error)) => Err(error),
296+
//! }
290297
//! })
291298
//! }
292299
//!
293300
//! /// `futures` version of `Serial.write`
294301
//! ///
295302
//! /// This returns a future that must be polled to completion
296-
//! fn write<S>(serial: S, byte: u8) -> impl Future<Item = (), Error = S::Error>
303+
//! fn write<S>(serial: S, byte: u8) -> impl Future<Item = S, Error = S::Error>
297304
//! where
298305
//! S: hal::serial::Write<u8>,
299306
//! {
300-
//! future::poll_fn(move || {
301-
//! Ok(Async::Ready(try_nb!(serial.write(byte))))
307+
//! future::loop_fn(serial, move |mut serial| {
308+
//! match serial.write(byte) {
309+
//! Ok(()) => Ok(Loop::Break(serial)),
310+
//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)),
311+
//! Err(nb::Error::Other(error)) => Err(error),
312+
//! }
302313
//! })
303314
//! }
304315
//!

0 commit comments

Comments
 (0)