Skip to content

Commit 4bed6b9

Browse files
bors[bot]dbrgn
andcommitted
Merge #18
18: Move to digital v2 traits r=nastevens a=dbrgn The v1 traits are deprecated because they don't have a way to report errors. Gets rid of the deprecation warnings (which are hard errors until #17 is merged). Co-authored-by: Danilo Bargen <[email protected]>
2 parents 235d9db + fe86849 commit 4bed6b9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/lib.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,31 @@ impl Pin {
115115
}
116116
}
117117

118-
impl hal::digital::OutputPin for Pin {
119-
fn set_low(&mut self) {
120-
self.0.set_value(0).unwrap()
118+
impl hal::digital::v2::OutputPin for Pin {
119+
type Error = sysfs_gpio::Error;
120+
121+
fn set_low(&mut self) -> Result<(), Self::Error> {
122+
self.0.set_value(0)
121123
}
122124

123-
fn set_high(&mut self) {
124-
self.0.set_value(1).unwrap()
125+
fn set_high(&mut self) -> Result<(), Self::Error> {
126+
self.0.set_value(1)
125127
}
126128
}
127129

128-
impl hal::digital::InputPin for Pin {
129-
fn is_high(&self) -> bool{
130-
if !self.0.get_active_low().unwrap() {
131-
self.0.get_value().unwrap() != 0
130+
impl hal::digital::v2::InputPin for Pin {
131+
type Error = sysfs_gpio::Error;
132+
133+
fn is_high(&self) -> Result<bool, Self::Error> {
134+
if !self.0.get_active_low()? {
135+
self.0.get_value().map(|val| val != 0)
132136
} else {
133-
self.0.get_value().unwrap() == 0
137+
self.0.get_value().map(|val| val == 0)
134138
}
135139
}
136140

137-
fn is_low(&self) -> bool{
138-
!self.is_high()
141+
fn is_low(&self) -> Result<bool, Self::Error> {
142+
self.is_high().map(|val| !val)
139143
}
140144
}
141145

0 commit comments

Comments
 (0)