@@ -255,15 +255,13 @@ where
255
255
M : PinMode ,
256
256
F : FnOnce ( & mut Pin < P , N , M > ) -> R ,
257
257
{
258
- self . mode :: < M > ( ) ;
258
+ self . mode :: < M > ( ) ; // change physical mode, without changing typestate
259
259
260
260
// This will reset the pin back to the original mode when dropped.
261
261
// (so either when `with_mode` returns or when `f` unwinds)
262
- let _resetti = ResetMode { pin : self } ;
263
-
264
- let mut witness = Pin :: new ( ) ;
262
+ let mut resetti = ResetMode :: < P , N , M , MODE > :: new ( ) ;
265
263
266
- f ( & mut witness )
264
+ f ( & mut resetti . pin )
267
265
}
268
266
269
267
/// Temporarily configures this pin as a input.
@@ -341,11 +339,22 @@ where
341
339
}
342
340
}
343
341
344
- struct ResetMode < ' a , const P : char , const N : u8 , ORIG : PinMode > {
345
- pin : & ' a mut Pin < P , N , ORIG > ,
342
+ /// Wrapper around a pin that transitions the pin to mode ORIG when dropped
343
+ struct ResetMode < const P : char , const N : u8 , CURRENT : PinMode , ORIG : PinMode > {
344
+ pub pin : Pin < P , N , CURRENT > ,
345
+ _mode : PhantomData < ORIG > ,
346
346
}
347
-
348
- impl < ' a , const P : char , const N : u8 , ORIG : PinMode > Drop for ResetMode < ' a , P , N , ORIG > {
347
+ impl < const P : char , const N : u8 , CURRENT : PinMode , ORIG : PinMode > ResetMode < P , N , CURRENT , ORIG > {
348
+ fn new ( ) -> Self {
349
+ Self {
350
+ pin : Pin :: new ( ) ,
351
+ _mode : PhantomData ,
352
+ }
353
+ }
354
+ }
355
+ impl < const P : char , const N : u8 , CURRENT : PinMode , ORIG : PinMode > Drop
356
+ for ResetMode < P , N , CURRENT , ORIG >
357
+ {
349
358
fn drop ( & mut self ) {
350
359
self . pin . mode :: < ORIG > ( ) ;
351
360
}
0 commit comments