103
103
//! // ..
104
104
//!
105
105
//! /// "waits" until the count down is over
106
- //! fn wait (&mut self) -> nb::Result<(), Infallible>;
106
+ //! fn try_wait (&mut self) -> nb::Result<(), Infallible>;
107
107
//! }
108
108
//!
109
109
//! # fn main() {}
257
257
//! use stm32f30x_hal::{Led, Serial1, Timer6};
258
258
//! use std::convert::Infallible;
259
259
//!
260
- //! /// `futures` version of `CountDown.wait `
260
+ //! /// `futures` version of `CountDown.try_wait `
261
261
//! ///
262
262
//! /// This returns a future that must be polled to completion
263
263
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Infallible>
266
266
//! {
267
267
//! let mut timer = Some(timer);
268
268
//! future::poll_fn(move || {
269
- //! try_nb!(timer.as_mut().unwrap().wait ());
269
+ //! try_nb!(timer.as_mut().unwrap().try_wait ());
270
270
//!
271
271
//! Ok(Async::Ready(timer.take().unwrap()))
272
272
//! })
349
349
//! }
350
350
//!
351
351
//! # mod stm32f30x_hal {
352
- //! # use std ::convert::Infallible;
352
+ //! # use core ::convert::Infallible;
353
353
//! # pub struct Timer6;
354
354
//! # impl ::hal::timer::CountDown for Timer6 {
355
355
//! # type Time = ();
356
356
//! #
357
- //! # fn start <T>(&mut self, _: T) where T: Into<()> {}
358
- //! # fn wait (&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
357
+ //! # fn try_start <T>(&mut self, _: T) -> Result<(), Infallible> where T: Into<()> {}
358
+ //! # fn try_wait (&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
359
359
//! # }
360
360
//! #
361
361
//! # pub struct Serial1;
509
509
//!
510
510
//! use hal::prelude::*;
511
511
//!
512
- //! enum Error<E > {
512
+ //! enum Error<SE, TE > {
513
513
//! /// Serial interface error
514
- //! Serial(E),
515
- //! TimedOut,
514
+ //! Serial(SE),
515
+ //! /// Timeout error
516
+ //! TimedOut(TE),
516
517
//! }
517
518
//!
518
519
//! fn read_with_timeout<S, T>(
519
520
//! serial: &mut S,
520
521
//! timer: &mut T,
521
522
//! timeout: T::Time,
522
- //! ) -> Result<u8, Error<S::Error>>
523
+ //! ) -> Result<u8, Error<S::Error, T::Error >>
523
524
//! where
524
- //! T: hal::timer::CountDown,
525
+ //! T: hal::timer::CountDown<Error = ()> ,
525
526
//! S: hal::serial::Read<u8>,
526
527
//! {
527
- //! timer.start (timeout);
528
+ //! timer.try_start (timeout).map_err(Error::TimedOut)? ;
528
529
//!
529
530
//! loop {
530
531
//! match serial.read() {
536
537
//! Ok(byte) => return Ok(byte),
537
538
//! }
538
539
//!
539
- //! match timer.wait () {
540
+ //! match timer.try_wait () {
540
541
//! Err(nb::Error::Other(e)) => {
541
- //! // The error type specified by `timer.wait ()` is `!`, which
542
+ //! // The error type specified by `timer.try_wait ()` is `!`, which
542
543
//! // means no error can actually occur. The Rust compiler
543
544
//! // still forces us to provide this match arm, though.
544
545
//! unreachable!()
545
546
//! },
546
547
//! // no timeout yet, try again
547
548
//! Err(nb::Error::WouldBlock) => continue,
548
- //! Ok(()) => return Err(Error::TimedOut),
549
+ //! Ok(()) => return Err(Error::TimedOut(()) ),
549
550
//! }
550
551
//! }
551
552
//! }
@@ -949,8 +950,8 @@ pub trait PwmPin {
949
950
///
950
951
///
951
952
/// let before = qei.try_count().unwrap();
952
- /// timer.start (1.s());
953
- /// block!(timer.wait ());
953
+ /// timer.try_start (1.s()).unwrap( );
954
+ /// block!(timer.try_wait ());
954
955
/// let after = qei.try_count().unwrap();
955
956
///
956
957
/// let speed = after.wrapping_sub(before);
@@ -965,14 +966,14 @@ pub trait PwmPin {
965
966
/// # impl hal::Qei for Qei1 {
966
967
/// # type Error = Infallible;
967
968
/// # type Count = u16;
968
- /// # fn try_count(&self) -> Result<u16, Self::Error> { 0 }
969
+ /// # fn try_count(&self) -> Result<u16, Self::Error> { Ok(0) }
969
970
/// # fn try_direction(&self) -> Result<::hal::Direction, Self::Error> { unimplemented!() }
970
971
/// # }
971
972
/// # struct Timer6;
972
973
/// # impl hal::timer::CountDown for Timer6 {
973
974
/// # type Time = Seconds;
974
- /// # fn start <T>(&mut self, _: T) where T: Into<Seconds> {}
975
- /// # fn wait (&mut self) -> ::nb::Result<(), Infallible> { Ok(()) }
975
+ /// # fn try_start <T>(&mut self, _: T) -> Result<(), Infallible> where T: Into<Seconds> { Ok(()) }
976
+ /// # fn try_wait (&mut self) -> ::nb::Result<(), Infallible> { Ok(()) }
976
977
/// # }
977
978
/// ```
978
979
#[ cfg( feature = "unproven" ) ]
0 commit comments