You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
331: spi: enforce all traits have the same Error type. r=ryankurte a=Dirbaio
Previously discussed in #323, split off to its own PR now.
This PR enforces all SPI trait impls for a given type use the same Error associated type, by moving it to its own ErrorType trait.
## How breaking is this?
I believe this is not very breaking in practice (it won't make upgrading existing code to 1.0 harder), because:
- HALs already use the same error type for all methods (I haven't seen one that doesn't)
- Drivers already often add bounds to enforce the errors are the same. [Example](https://github.com/rust-iot/rust-radio-sx127x/blob/8188c20c89603dbda9592c40a8e3fc5b37769a00/src/lib.rs#L122). Without these bounds, propagating errors up would be more annoying, drivers would need even more generic types `SpiWriteError, SpiReadError, SpiTransferError, SpiTransactionalError`...
## Why is this good?
Traits being able to have different Error types is IMO a case of "bad freedom" for the HALs. Today's traits don't stop HALs from implementing them with different error types, but this would cause them to be incompatible with drivers with these bounds. If traits force error types to be the same, the problem is gone.
## What about other traits?
I believe this should be also applied to the other traits. I propose discussing this in the context of SPI here, and if the consensus is it's good I'll send PRs doing the same for the other traits.
Co-authored-by: Dario Nieuwenhuis <[email protected]>
0 commit comments