Skip to content

Commit a5c0e3c

Browse files
bors[bot]ryankurte
andcommitted
Merge #136
136: improved digital compatibility docs r=therealprof a=ryankurte Co-authored-by: Ryan Kurte <[email protected]>
2 parents 5b0e526 + 79ae58c commit a5c0e3c

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

src/digital/v1_compat.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
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)]
739
use super::v1;

src/digital/v2_compat.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
//! v2 compatibility shims
2-
//! this module adds implicit forward support to v1 digital traits
2+
//!
3+
//! 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)]
536
use super::v1;

0 commit comments

Comments
 (0)