Skip to content

Commit db09d73

Browse files
Merge #164
164: Make the digital::{v1, v2}::InputPin traits proven r=therealprof a=nils-van-zuijlen See #41 Previous attempt : #102 Co-authored-by: Nils VAN ZUIJLEN <[email protected]>
2 parents 8d520a7 + d9d1052 commit db09d73

File tree

5 files changed

+3
-27
lines changed

5 files changed

+3
-27
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212

1313
### Changed
14-
14+
- The current versions of `InputPin` have been proven. These are `digital::v1::InputPin`
15+
and `digital::v2::InputPin`.
1516

1617
## [v0.2.3] - 2019-05-09
1718

src/digital/v1.rs

-3
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,8 @@ pub mod toggleable {
131131

132132
/// Single digital input pin
133133
///
134-
/// *This trait is available if embedded-hal is built with the `"unproven"` feature.*
135-
///
136134
/// *This version of the trait is now deprecated. Please use the new `InputPin` trait in
137135
/// `digital::v2::InputPin`*.
138-
#[cfg(feature = "unproven")]
139136
pub trait InputPin {
140137
/// Is the input pin high?
141138
fn is_high(&self) -> bool;

src/digital/v1_compat.rs

-12
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ where
108108

109109
/// Wrapper to allow fallible `v2::InputPin` traits to be converted to `v1::InputPin` traits
110110
/// where errors will panic.
111-
#[cfg(feature = "unproven")]
112111
pub struct OldInputPin<T> {
113112
pin: T,
114113
}
115114

116-
#[cfg(feature = "unproven")]
117115
impl <T, E> OldInputPin<T>
118116
where
119117
T: v2::OutputPin<Error=E>,
@@ -126,7 +124,6 @@ where
126124

127125
}
128126

129-
#[cfg(feature = "unproven")]
130127
impl <T, E> From<T> for OldInputPin<T>
131128
where
132129
T: v2::InputPin<Error=E>,
@@ -139,7 +136,6 @@ where
139136

140137
/// Implementation of `v1::InputPin` trait for `v2::InputPin` fallible pins
141138
/// where errors will panic.
142-
#[cfg(feature = "unproven")]
143139
#[allow(deprecated)]
144140
impl <T, E> v1::InputPin for OldInputPin<T>
145141
where
@@ -224,15 +220,12 @@ mod tests {
224220
o.set_high();
225221
}
226222

227-
#[cfg(feature = "unproven")]
228223
use crate::digital::v1::InputPin;
229224

230-
#[cfg(feature = "unproven")]
231225
struct NewInputPinImpl {
232226
state: Result<bool, ()>,
233227
}
234228

235-
#[cfg(feature = "unproven")]
236229
impl v2::InputPin for NewInputPinImpl {
237230
type Error = ();
238231

@@ -244,13 +237,11 @@ mod tests {
244237
}
245238
}
246239

247-
#[cfg(feature = "unproven")]
248240
#[allow(deprecated)]
249241
struct OldInputPinConsumer<T: v1::InputPin> {
250242
_pin: T,
251243
}
252244

253-
#[cfg(feature = "unproven")]
254245
#[allow(deprecated)]
255246
impl <T>OldInputPinConsumer<T>
256247
where T: v1::InputPin
@@ -260,14 +251,12 @@ mod tests {
260251
}
261252
}
262253

263-
#[cfg(feature = "unproven")]
264254
#[test]
265255
fn v1_v2_input_explicit() {
266256
let i = NewInputPinImpl{state: Ok(false)};
267257
let _c: OldInputPinConsumer<OldInputPin<_>> = OldInputPinConsumer::new(i.into());
268258
}
269259

270-
#[cfg(feature = "unproven")]
271260
#[test]
272261
fn v1_v2_input_state() {
273262
let i: OldInputPin<_> = NewInputPinImpl{state: Ok(false)}.into();
@@ -276,7 +265,6 @@ mod tests {
276265
assert_eq!(i.is_high(), false);
277266
}
278267

279-
#[cfg(feature = "unproven")]
280268
#[test]
281269
#[should_panic]
282270
fn v1_v2_input_panic() {

src/digital/v2.rs

-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ pub mod toggleable {
124124
}
125125

126126
/// Single digital input pin
127-
///
128-
/// *This trait is available if embedded-hal is built with the `"unproven"` feature.*
129-
#[cfg(feature = "unproven")]
130127
pub trait InputPin {
131128
/// Error type
132129
type Error;

src/digital/v2_compat.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ where
7676
impl<T> v2::toggleable::Default for T where T: v1::toggleable::Default {}
7777

7878
/// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits
79-
#[cfg(feature = "unproven")]
8079
#[allow(deprecated)]
8180
impl <T> v2::InputPin for T
8281
where
@@ -176,13 +175,11 @@ mod tests {
176175
assert_eq!(o.state, false);
177176
}
178177

179-
#[cfg(feature = "unproven")]
180178
#[allow(deprecated)]
181179
struct OldInputPinImpl {
182180
state: bool
183181
}
184182

185-
#[cfg(feature = "unproven")]
186183
#[allow(deprecated)]
187184
impl v1::InputPin for OldInputPinImpl {
188185
fn is_low(&self) -> bool {
@@ -193,32 +190,28 @@ mod tests {
193190
}
194191
}
195192

196-
#[cfg(feature = "unproven")]
197193
struct NewInputPinConsumer<T: v2::InputPin> {
198194
_pin: T,
199195
}
200196

201-
#[cfg(feature = "unproven")]
202197
impl <T>NewInputPinConsumer<T>
203198
where T: v2::InputPin {
204199
pub fn new(pin: T) -> NewInputPinConsumer<T> {
205200
NewInputPinConsumer{ _pin: pin }
206201
}
207202
}
208203

209-
#[cfg(feature = "unproven")]
210204
#[test]
211205
fn v2_v1_input_implicit() {
212206
let i = OldInputPinImpl{state: false};
213207
let _c = NewInputPinConsumer::new(i);
214208
}
215209

216-
#[cfg(feature = "unproven")]
217210
#[test]
218211
fn v2_v1_input_state() {
219212
let mut i = OldInputPinImpl{state: false};
220213

221214
assert_eq!(v2::InputPin::is_high(&mut i).unwrap(), false);
222215
assert_eq!(v2::InputPin::is_low(&mut i).unwrap(), true);
223216
}
224-
}
217+
}

0 commit comments

Comments
 (0)