Skip to content

Commit 9189259

Browse files
committed
Make Capture trait fallible
1 parent f220317 commit 9189259

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -721,32 +721,33 @@ pub mod watchdog;
721721
/// # Capture1
722722
/// };
723723
///
724-
/// capture.set_resolution(1.ms());
724+
/// capture.try_set_resolution(1.ms()).unwrap();
725725
///
726-
/// let before = block!(capture.capture(Channel::_1)).unwrap();
727-
/// let after = block!(capture.capture(Channel::_1)).unwrap();
726+
/// let before = block!(capture.try_capture(Channel::_1)).unwrap();
727+
/// let after = block!(capture.try_capture(Channel::_1)).unwrap();
728728
///
729729
/// let period = after.wrapping_sub(before);
730730
///
731731
/// println!("Period: {} ms", period);
732732
/// }
733733
///
734-
/// # use std::convert::Infallible;
734+
/// # use core::convert::Infallible;
735735
/// # struct MilliSeconds(u32);
736736
/// # trait U32Ext { fn ms(self) -> MilliSeconds; }
737737
/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } }
738738
/// # struct Capture1;
739739
/// # enum Channel { _1 }
740740
/// # impl hal::Capture for Capture1 {
741+
/// # type Error = Infallible;
741742
/// # type Capture = u16;
742743
/// # type Channel = Channel;
743744
/// # type Error = Infallible;
744745
/// # type Time = MilliSeconds;
745-
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Infallible> { Ok(0) }
746-
/// # fn disable(&mut self, _: Channel) { unimplemented!() }
747-
/// # fn enable(&mut self, _: Channel) { unimplemented!() }
748-
/// # fn get_resolution(&self) -> MilliSeconds { unimplemented!() }
749-
/// # fn set_resolution<T>(&mut self, _: T) where T: Into<MilliSeconds> {}
746+
/// # fn try_capture(&mut self, _: Channel) -> ::nb::Result<u16, Self::Error> { Ok(0) }
747+
/// # fn try_disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
748+
/// # fn try_enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
749+
/// # fn try_get_resolution(&self) -> Result<MilliSeconds, Self::Error> { unimplemented!() }
750+
/// # fn try_set_resolution<T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<MilliSeconds> {}
750751
/// # }
751752
/// ```
752753
#[cfg(feature = "unproven")]
@@ -778,19 +779,19 @@ pub trait Capture {
778779
///
779780
/// NOTE that you must multiply the returned value by the *resolution* of
780781
/// this `Capture` interface to get a human time unit (e.g. seconds)
781-
fn capture(&mut self, channel: Self::Channel) -> nb::Result<Self::Capture, Self::Error>;
782+
fn try_capture(&mut self, channel: Self::Channel) -> nb::Result<Self::Capture, Self::Error>;
782783

783784
/// Disables a capture `channel`
784-
fn disable(&mut self, channel: Self::Channel);
785+
fn try_disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
785786

786787
/// Enables a capture `channel`
787-
fn enable(&mut self, channel: Self::Channel);
788+
fn try_enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
788789

789790
/// Returns the current resolution
790-
fn get_resolution(&self) -> Self::Time;
791+
fn try_get_resolution(&self) -> Result<Self::Time, Self::Error>;
791792

792793
/// Sets the resolution of the capture timer
793-
fn set_resolution<R>(&mut self, resolution: R)
794+
fn try_set_resolution<R>(&mut self, resolution: R) -> Result<(), Self::Error>
794795
where
795796
R: Into<Self::Time>;
796797
}

0 commit comments

Comments
 (0)