Skip to content

spi: enforce all traits have the same Error type. #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2022

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Dec 19, 2021

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. 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.

@Dirbaio Dirbaio requested a review from a team as a code owner December 19, 2021 08:34
@rust-highfive
Copy link

r? @therealprof

(rust-highfive has picked a reviewer for you, use r? to override)

@Dirbaio
Copy link
Member Author

Dirbaio commented Dec 20, 2021

Working HAL implementation for nRF chips here embassy-rs/embassy#552. Updating was quite straightforward as the HAL already used the same error type for all impls. No issues discovered.

burrbull
burrbull previously approved these changes Dec 20, 2021
eldruin
eldruin previously approved these changes Dec 20, 2021
Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea to me.
Opinions @rust-embedded/hal?

@Dirbaio Dirbaio changed the title spi: enforce all traits (nb+blocking) have the same Error type. spi: enforce all traits have the same Error type. Jan 11, 2022
@Dirbaio Dirbaio dismissed stale reviews from eldruin and burrbull via 37edca7 January 11, 2022 21:45
@Dirbaio
Copy link
Member Author

Dirbaio commented Jan 11, 2022

Friendly ping @eldruin @therealprof @ryankurte I guess if no one has any concerns in 23 days it's good to go?

Rebased

Copy link
Contributor

@ryankurte ryankurte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

bors r+

@bors bors bot merged commit 73c54d9 into rust-embedded:master Jan 11, 2022
bors bot added a commit that referenced this pull request Jan 12, 2022
338: digital: enforce all traits have the same Error type. r=therealprof a=Dirbaio

Equivalent of #331 for GPIO traits.

This one is a bit trickier, so it maybe warrants some discussion (this is the reason I've opened everything as separate PR's, sorry for the spam!):

- The bounds on `IoPin` are becoming very cursed, but I *think* they're correct... Is there some HAL out there implementing it, so that I can verify this doesn't break it?
- This forces the "input" and "output" errors to be the same. Perhaps we want to only unify Output and Input separately? In practice I don't think this will be an issue, as structs usually impl only Input or Output but not both (except with IoPin maybe?)

Co-authored-by: Dario Nieuwenhuis <[email protected]>
bors bot added a commit that referenced this pull request Jan 12, 2022
337: serial: enforce all traits have the same Error type. r=therealprof a=Dirbaio

Equivalent of #331 for serial.

Co-authored-by: Dario Nieuwenhuis <[email protected]>
bors bot added a commit that referenced this pull request Jan 12, 2022
336: i2c: enforce all traits have the same Error type. r=therealprof a=Dirbaio

Equivalent of #331 for i2c.

Co-authored-by: Dario Nieuwenhuis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Review is incomplete T-hal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants