@@ -11,21 +11,26 @@ pub struct OldOutputPin<T> {
11
11
pin : T ,
12
12
}
13
13
14
- impl < T , ERR > OldOutputPin < T >
14
+ impl < T , E > OldOutputPin < T >
15
15
where
16
- T : v2:: OutputPin < Error =ERR > ,
17
- ERR : core:: fmt:: Debug ,
16
+ T : v2:: OutputPin < Error =E > ,
17
+ E : core:: fmt:: Debug ,
18
18
{
19
19
/// Create a new OldOutputPin wrapper around a v2::OutputPin
20
20
pub fn new ( pin : T ) -> Self {
21
21
Self { pin}
22
22
}
23
+
24
+ /// Fetch a reference to the inner v2::OutputPin impl
25
+ pub fn inner ( & self ) -> & T {
26
+ & self . pin
27
+ }
23
28
}
24
29
25
- impl < T , ERR > From < T > for OldOutputPin < T >
30
+ impl < T , E > From < T > for OldOutputPin < T >
26
31
where
27
- T : v2:: OutputPin < Error =ERR > ,
28
- ERR : core:: fmt:: Debug ,
32
+ T : v2:: OutputPin < Error =E > ,
33
+ E : core:: fmt:: Debug ,
29
34
{
30
35
fn from ( pin : T ) -> Self {
31
36
OldOutputPin { pin}
@@ -34,10 +39,10 @@ where
34
39
35
40
/// Implementation of v1 OutputPin trait for v2 fallible output pins
36
41
#[ allow( deprecated) ]
37
- impl < T , ERR > v1:: OutputPin for OldOutputPin < T >
42
+ impl < T , E > v1:: OutputPin for OldOutputPin < T >
38
43
where
39
- T : v2:: OutputPin < Error =ERR > ,
40
- ERR : core:: fmt:: Debug ,
44
+ T : v2:: OutputPin < Error =E > ,
45
+ E : core:: fmt:: Debug ,
41
46
{
42
47
fn set_low ( & mut self ) {
43
48
self . pin . set_low ( ) . unwrap ( )
@@ -51,10 +56,10 @@ where
51
56
/// Implementation of v1 StatefulOutputPin trait for v2 fallible pins
52
57
#[ cfg( feature = "unproven" ) ]
53
58
#[ allow( deprecated) ]
54
- impl < T , ERR > v1:: StatefulOutputPin for OldOutputPin < T >
59
+ impl < T , E > v1:: StatefulOutputPin for OldOutputPin < T >
55
60
where
56
- T : v2:: StatefulOutputPin < Error =ERR > ,
57
- ERR : core:: fmt:: Debug ,
61
+ T : v2:: StatefulOutputPin < Error =E > ,
62
+ E : core:: fmt:: Debug ,
58
63
{
59
64
fn is_set_low ( & self ) -> bool {
60
65
self . pin . is_set_low ( ) . unwrap ( )
@@ -72,22 +77,27 @@ pub struct OldInputPin<T> {
72
77
}
73
78
74
79
#[ cfg( feature = "unproven" ) ]
75
- impl < T , ERR > OldInputPin < T >
80
+ impl < T , E > OldInputPin < T >
76
81
where
77
- T : v2:: OutputPin < Error =ERR > ,
78
- ERR : core:: fmt:: Debug ,
82
+ T : v2:: OutputPin < Error =E > ,
83
+ E : core:: fmt:: Debug ,
79
84
{
80
85
/// Create an OldInputPin wrapper around a v2::InputPin
81
86
pub fn new ( pin : T ) -> Self {
82
87
Self { pin}
83
88
}
89
+
90
+ /// Fetch a reference to the inner v2::InputPin impl
91
+ pub fn inner ( & self ) -> & T {
92
+ & self . pin
93
+ }
84
94
}
85
95
86
96
#[ cfg( feature = "unproven" ) ]
87
- impl < T , ERR > From < T > for OldInputPin < T >
97
+ impl < T , E > From < T > for OldInputPin < T >
88
98
where
89
- T : v2:: InputPin < Error =ERR > ,
90
- ERR : core:: fmt:: Debug ,
99
+ T : v2:: InputPin < Error =E > ,
100
+ E : core:: fmt:: Debug ,
91
101
{
92
102
fn from ( pin : T ) -> Self {
93
103
OldInputPin { pin}
@@ -97,10 +107,10 @@ where
97
107
/// Implementation of v0.2 InputPin trait for v0.3 fallible pins
98
108
#[ cfg( feature = "unproven" ) ]
99
109
#[ allow( deprecated) ]
100
- impl < T , ERR > v1:: InputPin for OldInputPin < T >
110
+ impl < T , E > v1:: InputPin for OldInputPin < T >
101
111
where
102
- T : v2:: InputPin < Error =ERR > ,
103
- ERR : core:: fmt:: Debug ,
112
+ T : v2:: InputPin < Error =E > ,
113
+ E : core:: fmt:: Debug ,
104
114
{
105
115
fn is_low ( & self ) -> bool {
106
116
self . pin . is_low ( ) . unwrap ( )
@@ -120,20 +130,24 @@ mod tests {
120
130
use crate :: digital:: v1;
121
131
use crate :: digital:: v2;
122
132
123
- struct NewOutputPinImpl {
124
- state : bool
133
+ use crate :: digital:: v1:: { InputPin , OutputPin } ;
134
+
135
+ #[ derive( Clone ) ]
136
+ struct NewOutputPinImpl {
137
+ state : bool ,
138
+ res : Result < ( ) , ( ) >
125
139
}
126
140
127
141
impl v2:: OutputPin for NewOutputPinImpl {
128
142
type Error = ( ) ;
129
143
130
144
fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
131
145
self . state = false ;
132
- Ok ( ( ) )
146
+ self . res
133
147
}
134
148
fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
135
149
self . state = true ;
136
- Ok ( ( ) )
150
+ self . res
137
151
}
138
152
}
139
153
@@ -153,24 +167,43 @@ mod tests {
153
167
154
168
#[ test]
155
169
fn v1_v2_output_explicit ( ) {
156
- let i = NewOutputPinImpl { state : false } ;
170
+ let i = NewOutputPinImpl { state : false , res : Ok ( ( ) ) } ;
157
171
let _c: OldOutputPinConsumer < OldOutputPin < _ > > = OldOutputPinConsumer :: new ( i. into ( ) ) ;
158
172
}
159
173
174
+ #[ test]
175
+ fn v1_v2_output_state ( ) {
176
+ let mut o: OldOutputPin < _ > = NewOutputPinImpl { state : false , res : Ok ( ( ) ) } . into ( ) ;
177
+
178
+ o. set_high ( ) ;
179
+ assert_eq ! ( o. inner( ) . state, true ) ;
180
+
181
+ o. set_low ( ) ;
182
+ assert_eq ! ( o. inner( ) . state, false ) ;
183
+ }
184
+
185
+ #[ test]
186
+ #[ should_panic]
187
+ fn v1_v2_output_panic ( ) {
188
+ let mut o: OldOutputPin < _ > = NewOutputPinImpl { state : false , res : Err ( ( ) ) } . into ( ) ;
189
+
190
+ o. set_high ( ) ;
191
+ }
192
+
160
193
#[ cfg( feature = "unproven" ) ]
161
194
struct NewInputPinImpl {
162
- state : bool ,
195
+ state : Result < bool , ( ) > ,
163
196
}
164
197
165
198
#[ cfg( feature = "unproven" ) ]
166
199
impl v2:: InputPin for NewInputPinImpl {
167
200
type Error = ( ) ;
168
201
169
202
fn is_low ( & self ) -> Result < bool , Self :: Error > {
170
- Ok ( ! self . state )
203
+ self . state . map ( |v| v == false )
171
204
}
172
205
fn is_high ( & self ) -> Result < bool , Self :: Error > {
173
- Ok ( self . state )
206
+ self . state . map ( |v| v == true )
174
207
}
175
208
}
176
209
@@ -193,8 +226,26 @@ mod tests {
193
226
#[ cfg( feature = "unproven" ) ]
194
227
#[ test]
195
228
fn v1_v2_input_explicit ( ) {
196
- let i = NewInputPinImpl { state : false } ;
229
+ let i = NewInputPinImpl { state : Ok ( false ) } ;
197
230
let _c: OldInputPinConsumer < OldInputPin < _ > > = OldInputPinConsumer :: new ( i. into ( ) ) ;
198
231
}
199
232
233
+ #[ cfg( feature = "unproven" ) ]
234
+ #[ test]
235
+ fn v1_v2_input_state ( ) {
236
+ let i: OldInputPin < _ > = NewInputPinImpl { state : Ok ( false ) } . into ( ) ;
237
+
238
+ assert_eq ! ( i. is_low( ) , true ) ;
239
+ assert_eq ! ( i. is_high( ) , false ) ;
240
+ }
241
+
242
+ #[ cfg( feature = "unproven" ) ]
243
+ #[ test]
244
+ #[ should_panic]
245
+ fn v1_v2_input_panic ( ) {
246
+ let i: OldInputPin < _ > = NewInputPinImpl { state : Err ( ( ) ) } . into ( ) ;
247
+
248
+ i. is_low ( ) ;
249
+ }
250
+
200
251
}
0 commit comments