Skip to content

Commit 0036746

Browse files
committed
Make Qei trait fallible
1 parent d2135c4 commit 0036746

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,24 +948,25 @@ pub trait PwmPin {
948948
/// };
949949
///
950950
///
951-
/// let before = qei.count();
951+
/// let before = qei.try_count().unwrap();
952952
/// timer.start(1.s());
953953
/// block!(timer.wait());
954-
/// let after = qei.count();
954+
/// let after = qei.try_count().unwrap();
955955
///
956956
/// let speed = after.wrapping_sub(before);
957957
/// println!("Speed: {} pulses per second", speed);
958958
/// }
959959
///
960-
/// # use std::convert::Infallible;
960+
/// # use core::convert::Infallible;
961961
/// # struct Seconds(u32);
962962
/// # trait U32Ext { fn s(self) -> Seconds; }
963963
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
964964
/// # struct Qei1;
965965
/// # impl hal::Qei for Qei1 {
966+
/// # type Error = Infallible;
966967
/// # type Count = u16;
967-
/// # fn count(&self) -> u16 { 0 }
968-
/// # fn direction(&self) -> ::hal::Direction { unimplemented!() }
968+
/// # fn try_count(&self) -> Result<u16, Self::Error> { 0 }
969+
/// # fn try_direction(&self) -> Result<::hal::Direction, Self::Error> { unimplemented!() }
969970
/// # }
970971
/// # struct Timer6;
971972
/// # impl hal::timer::CountDown for Timer6 {
@@ -978,14 +979,17 @@ pub trait PwmPin {
978979
// reason: needs to be re-evaluated in the new singletons world. At the very least this needs a
979980
// reference implementation
980981
pub trait Qei {
982+
/// Enumeration of `Qei` errors
983+
type Error;
984+
981985
/// The type of the value returned by `count`
982986
type Count;
983987

984988
/// Returns the current pulse count of the encoder
985-
fn count(&self) -> Self::Count;
989+
fn try_count(&self) -> Result<Self::Count, Self::Error>;
986990

987991
/// Returns the count direction
988-
fn direction(&self) -> Direction;
992+
fn try_direction(&self) -> Result<Direction, Self::Error>;
989993
}
990994

991995
/// Count direction

0 commit comments

Comments
 (0)