-
Notifications
You must be signed in to change notification settings - Fork 57
Error type #10
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
Error type #10
Conversation
Thanks for the PR @AerialX. Initially, I like this approach. I'll take a deeper look later tonight. |
/// Interface to an I2C Slave Device from an I2C Master | ||
/// | ||
/// Typical implementations will store state with references to the bus | ||
/// in use and the address of the slave device. The trait is based on the | ||
/// Linux i2cdev interface. | ||
pub trait I2CDevice { | ||
type 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'm wondering if there should be any additional traits required on this type. Nothing strikes me as really being worth requiring, so I think this is fine.
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 tried requiring std::error::Error
but then found out nix::Error
didn't impl it. I plan on addressing that in its own PR. fmt::Debug
wouldn't be too bad to require, since Result::unwrap
needs it.
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.
The other thing that could have an impact is if we want to support no_std
so devices could be used, for instance, in something like zinc. In that case, traits out of std (such as Debug
) pose a problem.
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.
That's fair! Debug
is in core though, only Error
is in std (and it really shouldn't be, but...)
Overall, I think I like this. Do you know of any other projects making use of this pattern in a similar fashion? I searched around rust itself and found some instances that are somewhat similar but not quite the same. I would be curious to know if this approach has been taken with some success in the past? |
I'm under the impression than an |
Ok, this looks like a great start. I'm going to merge and we can consider adding additional requirements on the |
Noticed that upstream implementation of |
Thoughts/comments on this approach?