Skip to content
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

remove void dep, use core::convert::Infallible instead #482

Merged
merged 2 commits into from
Jan 13, 2024

Conversation

rursprung
Copy link
Contributor

there's no need for the void dependency anymore. accordingly it can be removed. this will also help with implementing embedded-hal v1 traits as some of them rely on (or at least have better support for) core::convert::Infallible.

this is a breaking change for consumers as they have to e.g. replace void_unwrap() calls with unwrap().

the prelude is now no longer needed in most cases (potentally the whole mod prelude could be removed in the future as it now adds little benefit?).

note that this PR will conflict with #481; when one gets merged i'll have to rebase the other on top of it (though it will be a fairly trivial rebase). this is due to the fact that both modify the same lines in a few places. merging this one here first might be easier as the other one is smaller.

Copy link
Owner

@Rahix Rahix left a comment

Choose a reason for hiding this comment

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

Yeah, it's time to drop void. However in my eyes it isn't quite as simple as this. I am really not a fan of switching to regular .unwrap() in all the example code. Please check rust-embedded/embedded-hal#329 for a detailed discussion of the reasons why. This linked issue also has the solution I'd prefer to use in our examples: The unwrap-infallible crate. I think we should put it into the avr-hal prelude as the direct replacement for ResultVoidExt.

@Rahix Rahix linked an issue Jan 11, 2024 that may be closed by this pull request
rursprung and others added 2 commits January 13, 2024 16:19
there's no need for the `void` dependency anymore. accordingly it can be
removed. this will also help with implementing `embedded-hal` v1 traits
as some of them rely on (or at least have better support for)
`core::convert::Infallible`.

this is a breaking change for consumers as they have to e.g. replace
`void_unwrap()` calls with `unwrap()`.
After removing `void`, we're still missing a way to explicitly unwrap
infallible results such that it is clear that no panic can occur in this
location.  Because the standard library does not yet provide a solution
to this, let's use the `unwrap-infallible` crate [1] in the meantime.

This topic was also discussed in more detail in the embedded-hal project [2].

[1]: https://crates.io/crates/unwrap-infallible
[2]: rust-embedded/embedded-hal#329
@Rahix Rahix force-pushed the remove-void-dependency branch from fc90c0a to 4f38d8c Compare January 13, 2024 15:34
@Rahix
Copy link
Owner

Rahix commented Jan 13, 2024

I took the liberty to add the unwrap_infallible here so it's part of the same PR :)

@Rahix Rahix merged commit 1c08c35 into Rahix:main Jan 13, 2024
46 checks passed
@rursprung rursprung deleted the remove-void-dependency branch January 14, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of void and replacement with core::convert::Infallible
2 participants