-
Notifications
You must be signed in to change notification settings - Fork 211
Embedded error #218
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
Closed
Closed
Embedded error #218
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
940af7c
Added embedded_error to dependencies and re-export in prelude
therealprof 5e2eaa0
Use embedded_error::GpioError as Error type in GPIO
therealprof a3db2bb
Use embedded_error::SerialError as Error type in serial implementation
therealprof c19179e
Use embedded_error::SpiError as Error type in SPI implementation
therealprof 0ef237e
Use embedded_error::I2cError as Error type in I2C implementation
therealprof d70cde9
Add entry to CHANGELOG.md
therealprof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the other errors, I see the advantages, but replacing infallible by some non empty error, that's not great. I personally into_ok (a personal implementation for stable) on these errors, and it would not be possible after this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't make it uniform then we can't use this universally with drivers and applications, this is just a preview of what's to come in
embedded-hal
. There're plenty of cases like on a Raspberry Pi or behind GPIO expanders where GPIO is not infallible.What is
into_ok
? And how is it different from.ok()
? I don't think applications will change a lot but there might be a slight size overhead (not sure, really,Infallible
is also not quite ideal). If you have any ideas for improvement, I'd be all ears.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case would you need to know the error? Can you point on real example? I suppose some intermediate driver between embedded_hal and another driver where you have to manage some kind of error?
https://doc.rust-lang.org/core/result/enum.Result.html#method.into_ok and my "waiting to stabilise implementation" https://github.com/TeXitoi/keyseebee/blob/master/firmware/src/main.rs#L32-L42
That's an infallible
.ok().unwrap()
. As I know I don't have to manage error, I can remove the complexity of managing them for nothing. And it won't be possible anymore with this modification.Maybe we can have
Error: Into<GpioError>
andInfallible
can implement this conversion. But it will complexify the interface.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for example. No, I don't have an example yet but support for fallible GPIOs has been requested a few times and was incorporated into
embedded-hal
(aka thedigital::v2
debacle).When we change the Error types in
embedded-hal
the bounds will beInto<GpioError> + Clone + Debug
. I don't think we can implementInto<GpioError>
forInfallible
but if you have any idea how to solve that your input would certainly be appreciated over at rust-embedded/embedded-hal#229.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing Into for Infallible is easy: you just have to implement From, that you should implement if possible instead of Into anyway: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=86a6dabe6ccc820f756c03718d5e4cc4
Will try to look at the linked issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do a PR for implementing From for *Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be careful with doing that for the other Error. Many (most?) of the other peripherals are impossible to implement correctly in an
Infallible
way and I'd be wary to add a loophole to avoid a correct implementation out of the gate; we can always add it later if it makes sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken, only embedded-error can implement
From<Infallible>
for its types, and at least mathematically/logically, this conversion should exist (and there's only one implementation "up to canonical isomorphism"...). So I think the implementation should be added, with warnings about (peripheral) implementation correctness, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickray Yes, adding it to
embedded-error
and usingInfallible
at least for GPIO is what we were talking about.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a different proposition: rust-embedded/embedded-hal#229 (comment)
I'll wait a bit the feedbacks before doing a PR to embedded-error, if you don't mind.