-
Notifications
You must be signed in to change notification settings - Fork 223
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
digital
operations do not allow error propagation
#95
Comments
Seems like a good candidate for some The downside is this would result in two possible digital IO interfaces. |
@ryankurte Sounds good to me :) |
I may be missing something, but can't we just add an associated error type to the existing traits, and set those to (Update: Part of my comment is factually wrong.) |
Hmm, I think maybe that could work for |
pub trait InputPin {
type Error;
fn is_high(&self) -> Result<bool, Self::Error>;
} |
I just noticed that my previous comment about the stabilization of |
@hannobraun that'd also be a good approach, I do like the idea of only one interface. My concerns about that are that we'll break everything existing, which is ok but also not insignificant friction to users, and what the overhead is / whether it'll be optimised out for the infallible case. That said, maybe that's a question of optimiser behaviour, and the more I think about it the more I like the idea of pin errors always bubbling through in a sensible way. |
@ryankurte Yeah, the breakage is a legitimate concern. I don't think it can be avoided though. I've come to the conclusion that keeping the infallible traits would just be a bad idea. An implementation that has to deal with errors has three options regarding what to do about the infallible traits:
Given those options, we can't recommend that drivers use the infallible traits, as it will either cause them problems or restrict them in their portability. But since they're simpler than the fallible ones, many drivers probably will use them. I think that leaves us with two viable options:
I prefer option 1. Aside: An |
True, I'm onboard with moving everything to be fallible. Maybe we could open another issue wrt. communicating breaking changes and releases for embedded-hal downstream projects? @eldruin if you're still interested a PR updating the digital traits to use fallible types would be excellent! You can look at the blocking SPI traits for examples, afaik anything which returns data should return |
Ok, I was mostly concerned about the breakage but I see your points. |
Thank you! Maybe we should alleviate the breakage by doing the following:
That way, there's one full release cycle where the old traits are deprecated and people can migrate. With the next breaking release after that, all they'll have to do is update the name of the traits. Thoughts? |
Hmm, I like the idea of alleviating the issue, it but that seems to kindof double the breakage in code changes required? Find and replace is easy enough, but, slightly annoying to have to go through the code to fix things twice. I wonder if for the proven traits we could do it with feature flags to switch between them. That said, we are 0.x, people can choose when to update HAL versions, and by doing either we're causing fragmentation. If we could poll for broader consensus from the wg / some heavy users maybe it'd be simpler for everyone just to replace it all at once? |
You're right. I like your solution better. There's an open pull request now: #97 I think we should direct further discussion there. |
This has been solved in #108 |
Hey, thanks for all the effort! Might just keep this open until we've got the compatibility shim in place and a release done. |
127: Digital v1 <-> v2 compatibility wrappers and shims r=japaric a=ryankurte This PR introduces implicit v1 -> v2 (forward) compatibility, and explicit wrapper types for v2 -> v1 (reverse) compatibility between digital trait versions as a final step for #95, as well as moving the deprecated v1 traits to a re-exported module for clarity. As @japaric pointed out, it is not feasible to have implicit compatibility in both directions, so it seemed reasonable to make regression explicit as it hides an `.unwrap()` on failure. @therealprof, @hannobraun, @eldruin what do you think of this approach? I think it probably needs more documentation, though I am definitely open to suggestions as to what / where. See also: #100, #92, #102. Co-authored-by: Ryan Kurte <ryankurte@gmail.com> Co-authored-by: Diego Barrios Romero <eldruin@gmail.com> Co-authored-by: Daniel Egger <daniel@eggers-club.de>
woooo! |
Currently operations defined in the
digital
module traits do not allow error propagation.For example, in an I2C I/O expander driver I am writing I want to provide access to the individual pins as a bunch of
Px
structs implementingOutputPin
andInputPin
. Setting a pin or reading it involves I2C communication, which could fail.At the moment I just panic if there was a problem for either reading or writing.
The same would happen with the other traits:
StatefulOutputPin
andToggleableOutputPin
Another example from @caemor:
Discussion started here
The text was updated successfully, but these errors were encountered: