@@ -17,6 +17,9 @@ They are provided as early previews for community testing and preparation for th
1717If you use an alpha release, we recommend you choose an exact version specification in your
1818` Cargo.toml ` like: ` embedded-hal = "=1.0.0-alpha.2" `
1919
20+ See below for a way to implement both an ` embedded-hal ` ` 0.2.x ` version and an ` -alpha ` version
21+ side by side in a HAL.
22+
2023[ #177 ] : https://github.com/rust-embedded/embedded-hal/issues/177
2124
2225## How-to: add a new trait
5457
5558[ awesome-embedded-rust ] : https://github.com/rust-embedded/awesome-embedded-rust#driver-crates
5659
60+ ### Adding support for an ` embedded-hal ` ` -alpha ` version in a HAL implementation
61+
62+ It is possible for HAL implementations to support both the latest ` 0.2.x ` version of ` embedded-hal `
63+ as well as the latest ` 1.0.0-alpha ` version side by side. This has several big advantadges:
64+ - Allows for a more gradual upgrade process within the community.
65+ - Allows for a faster upgrade to ` 1.0 ` once it comes out.
66+ - Provides more oportunities to test the new ` embedded-hal ` version.
67+
68+ This approach has been implemented in [ LPC8xx HAL] ( https://github.com/lpc-rs/lpc8xx-hal ) . Here are the steps:
69+
70+ 1 . Add a dependency to the latest ` embedded-hal ` version to ` Cargo.toml ` .
71+ Use the ` package ` attribute to refer to it by another name, to prevent name collision
72+ ([ example] ( https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/Cargo.toml#L44-L46 ) ).
73+ 2 . Import the traits into the module where they should be implemented.
74+ Change their name using ` as ` to prevent name collisions
75+ ([ example] ( https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/src/gpio.rs#L49-L53 ) ).
76+ 3 . Implement the traits next to their non-alpha versions
77+ ([ example] ( https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/src/gpio.rs#L767-L782 ) ).
78+
79+ While none of this is hard, some HAL maintainers might prefer not to add a dependency on an alpha version.
80+ The main drawback of this approach is that it requires ongoing updates, as new ` embedded-hal ` alpha versions come out.
81+ As stated before, ` embedded-hal ` ` -alpha ` versions are _ not guaranteed_ to be compatible with each other.
82+
5783## Minimum Supported Rust Version (MSRV)
5884
5985This crate is guaranteed to compile on stable Rust 1.35 and up. It * might*
0 commit comments