File tree Expand file tree Collapse file tree 2 files changed +67
-4
lines changed Expand file tree Collapse file tree 2 files changed +67
-4
lines changed Original file line number Diff line number Diff line change 1- //! v1 compatibility wrapper
2- //! this module adds reverse support for v2 digital traits
3- //! v2 traits must be explicitly cast to the v1 version using `.into()`,
4- //! and will panic on internal errors
1+ //! v1 compatibility wrappers
2+ //!
3+ //! this module provides wrappers to support use of v2 implementations with
4+ //! v1 consumers. v2 traits must be explicitly cast to the v1 version using
5+ //! `.into()`, and will panic on internal errors
6+ //!
7+ //! ```
8+ //! extern crate embedded_hal;
9+ //! use embedded_hal::digital::{v1, v2, v1_compat::OldOutputPin};
10+ //!
11+ //! struct NewOutputPinImpl {}
12+ //!
13+ //! impl v2::OutputPin for NewOutputPinImpl {
14+ //! type Error = ();
15+ //! fn set_low(&mut self) -> Result<(), Self::Error> { Ok(()) }
16+ //! fn set_high(&mut self) -> Result<(), Self::Error>{ Ok(()) }
17+ //! }
18+ //!
19+ //! struct OldOutputPinConsumer<T: v1::OutputPin> {
20+ //! _pin: T,
21+ //! }
22+ //!
23+ //! impl <T>OldOutputPinConsumer<T>
24+ //! where T: v1::OutputPin {
25+ //! pub fn new(pin: T) -> OldOutputPinConsumer<T> {
26+ //! OldOutputPinConsumer{ _pin: pin }
27+ //! }
28+ //! }
29+ //!
30+ //! fn main() {
31+ //! let pin = NewOutputPinImpl{};
32+ //! let _consumer: OldOutputPinConsumer<OldOutputPin<_>> = OldOutputPinConsumer::new(pin.into());
33+ //! }
34+ //! ```
35+ //!
36+
537
638#[ allow( deprecated) ]
739use super :: v1;
Original file line number Diff line number Diff line change 11//! v2 compatibility shims
2+ //!
23//! this module adds implicit forward support to v1 digital traits
4+ //! allowing v1 implementations to be directly used with v2 consumers.
5+ //!
6+ //! ```
7+ //! extern crate embedded_hal;
8+ //! use embedded_hal::digital::{v1, v2};
9+ //!
10+ //! struct OldOutputPinImpl { }
11+ //!
12+ //! impl v1::OutputPin for OldOutputPinImpl {
13+ //! fn set_low(&mut self) { }
14+ //! fn set_high(&mut self) { }
15+ //! }
16+ //!
17+ //! struct NewOutputPinConsumer<T: v2::OutputPin> {
18+ //! _pin: T,
19+ //! }
20+ //!
21+ //! impl <T>NewOutputPinConsumer<T>
22+ //! where T: v2::OutputPin {
23+ //! pub fn new(pin: T) -> NewOutputPinConsumer<T> {
24+ //! NewOutputPinConsumer{ _pin: pin }
25+ //! }
26+ //! }
27+ //!
28+ //! fn main() {
29+ //! let pin = OldOutputPinImpl{};
30+ //! let _consumer = NewOutputPinConsumer::new(pin);
31+ //! }
32+ //! ```
33+ //!
334
435#[ allow( deprecated) ]
536use super :: v1;
You can’t perform that action at this time.
0 commit comments