Skip to content

Commit ac1673e

Browse files
committed
Rename digital trait methods try_*
1 parent fc62243 commit ac1673e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/digital.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ pub trait OutputPin {
99
///
1010
/// *NOTE* the actual electrical state of the pin may not actually be low, e.g. due to external
1111
/// electrical sources
12-
fn set_low(&mut self) -> Result<(), Self::Error>;
12+
fn try_set_low(&mut self) -> Result<(), Self::Error>;
1313

1414
/// Drives the pin high
1515
///
1616
/// *NOTE* the actual electrical state of the pin may not actually be high, e.g. due to external
1717
/// electrical sources
18-
fn set_high(&mut self) -> Result<(), Self::Error>;
18+
fn try_set_high(&mut self) -> Result<(), Self::Error>;
1919
}
2020

2121
/// Push-pull output pin that can read its output state
@@ -26,12 +26,12 @@ pub trait StatefulOutputPin: OutputPin {
2626
/// Is the pin in drive high mode?
2727
///
2828
/// *NOTE* this does *not* read the electrical state of the pin
29-
fn is_set_high(&self) -> Result<bool, Self::Error>;
29+
fn try_is_set_high(&self) -> Result<bool, Self::Error>;
3030

3131
/// Is the pin in drive low mode?
3232
///
3333
/// *NOTE* this does *not* read the electrical state of the pin
34-
fn is_set_low(&self) -> Result<bool, Self::Error>;
34+
fn try_is_set_low(&self) -> Result<bool, Self::Error>;
3535
}
3636

3737
/// Output pin that can be toggled
@@ -48,7 +48,7 @@ pub trait ToggleableOutputPin {
4848
type Error;
4949

5050
/// Toggle pin output.
51-
fn toggle(&mut self) -> Result<(), Self::Error>;
51+
fn try_toggle(&mut self) -> Result<(), Self::Error>;
5252
}
5353

5454
/// If you can read **and** write the output state, a pin is
@@ -57,7 +57,7 @@ pub trait ToggleableOutputPin {
5757
/// ```
5858
/// use embedded_hal::digital::{OutputPin, StatefulOutputPin, ToggleableOutputPin};
5959
/// use embedded_hal::digital::toggleable;
60-
/// use std::convert::Infallible;
60+
/// use core::convert::Infallible;
6161
///
6262
/// /// A virtual output pin that exists purely in software
6363
/// struct MyPin {
@@ -67,21 +67,21 @@ pub trait ToggleableOutputPin {
6767
/// impl OutputPin for MyPin {
6868
/// type Error = Infallible;
6969
///
70-
/// fn set_low(&mut self) -> Result<(), Self::Error> {
70+
/// fn try_set_low(&mut self) -> Result<(), Self::Error> {
7171
/// self.state = false;
7272
/// Ok(())
7373
/// }
74-
/// fn set_high(&mut self) -> Result<(), Self::Error> {
74+
/// fn try_set_high(&mut self) -> Result<(), Self::Error> {
7575
/// self.state = true;
7676
/// Ok(())
7777
/// }
7878
/// }
7979
///
8080
/// impl StatefulOutputPin for MyPin {
81-
/// fn is_set_low(&self) -> Result<bool, Self::Error> {
81+
/// fn try_is_set_low(&self) -> Result<bool, Self::Error> {
8282
/// Ok(!self.state)
8383
/// }
84-
/// fn is_set_high(&self) -> Result<bool, Self::Error> {
84+
/// fn try_is_set_high(&self) -> Result<bool, Self::Error> {
8585
/// Ok(self.state)
8686
/// }
8787
/// }
@@ -90,10 +90,10 @@ pub trait ToggleableOutputPin {
9090
/// impl toggleable::Default for MyPin {}
9191
///
9292
/// let mut pin = MyPin { state: false };
93-
/// pin.toggle().unwrap();
94-
/// assert!(pin.is_set_high().unwrap());
95-
/// pin.toggle().unwrap();
96-
/// assert!(pin.is_set_low().unwrap());
93+
/// pin.try_toggle().unwrap();
94+
/// assert!(pin.try_is_set_high().unwrap());
95+
/// pin.try_toggle().unwrap();
96+
/// assert!(pin.try_is_set_low().unwrap());
9797
/// ```
9898
#[cfg(feature = "unproven")]
9999
pub mod toggleable {
@@ -111,11 +111,11 @@ pub mod toggleable {
111111
type Error = P::Error;
112112

113113
/// Toggle pin output
114-
fn toggle(&mut self) -> Result<(), Self::Error> {
115-
if self.is_set_low()? {
116-
self.set_high()
114+
fn try_toggle(&mut self) -> Result<(), Self::Error> {
115+
if self.try_is_set_low()? {
116+
self.try_set_high()
117117
} else {
118-
self.set_low()
118+
self.try_set_low()
119119
}
120120
}
121121
}
@@ -127,8 +127,8 @@ pub trait InputPin {
127127
type Error;
128128

129129
/// Is the input pin high?
130-
fn is_high(&self) -> Result<bool, Self::Error>;
130+
fn try_is_high(&self) -> Result<bool, Self::Error>;
131131

132132
/// Is the input pin low?
133-
fn is_low(&self) -> Result<bool, Self::Error>;
133+
fn try_is_low(&self) -> Result<bool, Self::Error>;
134134
}

0 commit comments

Comments
 (0)