Skip to content

Commit 4ba7aa7

Browse files
committed
Update guide to current state
1 parent b7e45ed commit 4ba7aa7

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

MIGRATING-0.2-1.0.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
- [Trait organization](#trait-organization)
88
- [Fallibility](#fallibility)
99
- [Method renaming](#method-renaming)
10+
- [SPI transfer return type](#spi-transfer-return-type)
11+
- [Error type bounds](#error-type-bounds)
1012
- [`nb` dependency](#nb-dependency)
1113
- [Prelude](#prelude)
1214
- [`rng` module](#rng-module)
15+
- [Removed blanket implementations](#removed-blanket-implementations)
1316
- [Features](#features)
1417
- [Use-case-specific help](#use-case-specific-help)
1518
- [For driver authors](#for-driver-authors)
@@ -19,9 +22,11 @@
1922

2023
## Trait organization
2124

22-
All traits have been organized in modules depending on their execution model. That includes `blocking` and `nb` for
25+
All traits have been organized in modules for each feature, each of these containing sub-modules depending on their execution model. That includes `blocking` and `nb` for
2326
non-blocking. In the future when we add asynchronous traits, we envision adding a `futures` (or similarly-named) module.
2427

28+
Execution-model-independent definitions have been moved into the feature module. For example, SPI `Phase` is now defined in `embedded_hal::spi::Phase`. For convenience, these definitions are reexported in both of its blocking and non-blocking submodules.
29+
2530
## Fallibility
2631

2732
All trait methods are now fallible so that they can be used in any possible situation.
@@ -76,6 +81,38 @@ into the relevant scope. This is the reason why we have removed the prelude.
7681

7782
For more on this, see [Prelude](#prelude).
7883

84+
## SPI transfer return type
85+
86+
The `transfer()` method in the trait `spi::blocking::Transfer` previously returned
87+
a slice of the output data.
88+
This slice is the same as the output buffer which is passed to the method, though, thus redundant and potentially confusing.
89+
The `transfer()` method now returns `Result<(), Self::Error>`.
90+
If you were using this return value, adapting the code should be straight forward by simply using the reception buffer which is passed.
91+
See an example:
92+
```rust
93+
let tx_data = [1, 2, 3, 4];
94+
let mut rx_data = [0; 4];
95+
let data = spi.transfer(&tx_data, &mut rx_data)?;
96+
println!("{:?}", data);
97+
// There is no need to do `let data = `, since we already have the data in `rx_data`.
98+
// Do this instead:
99+
spi.transfer(&tx_data, &mut rx_data)?;
100+
println!("{:?}", rx_data);
101+
```
102+
103+
## Error type bounds
104+
105+
All associated error types are now required to implement `core::fmt::Debug`.
106+
Usually it is enough to add a `#[derive(Debug)]` clause to your error types. For example:
107+
108+
```diff
109+
+ #[derive(Debug)]
110+
pub enum MyError {
111+
InvalidInputData,
112+
// ...
113+
}
114+
```
115+
79116
## `nb` dependency
80117

81118
The `Result` type and `block!` macro from the [`nb`] crate are now reexported in `embeddeh_hal::nb`.
@@ -116,6 +153,13 @@ The `rng` module and its traits have been removed in favor of the [`rand_core`]
116153

117154
[`rand_core`]: https://crates.io/crates/rand_core
118155

156+
## Removed blanket implementations
157+
158+
There were several blanket implementations of blocking traits using the non-blocking
159+
traits as a base.
160+
Due to their relative simplicity and some technical concerns, these have been removed.
161+
Implementing them yourself is now necessary. This should be straight-forward.
162+
119163
## Features
120164

121165
The `unproven` feature has been removed and the traits have been marked as proven.

0 commit comments

Comments
 (0)