-
Notifications
You must be signed in to change notification settings - Fork 241
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
Clean up the I2C impls. #758
base: main
Are you sure you want to change the base?
Conversation
True, I’m mostly done with the tests of the blocking APIs. |
I'd like to not block an embedded-hal 1.0 compatible release on async changes, but if that's going to be quick, then sure. Or I can drop this and go and extract the non-async bits from 753. |
@jonathanpallant: Is there anything left in this PR that's not covered by the already merged #747? |
Wearing my @thejpster hat, I'll try and look this weekend. |
70a2fa2
to
0f69060
Compare
OK, so I spent some time cleaning this up ... and I'm not sure I like it. Well, I do like the idea of the types having inherent methods so that functionality just works, without having to import a trait to make it work. Also it's easier to read about the functionality in the docs because it's not hidden behind a trait. But, if you have an inherent method which has the same name as an async trait method, you get the inherent one in preference, which does not have the same return type. |
Also we have inherent methods, so you can ignore the Embedded HAL traits if you want (makes the examples simpler too). Whilst doing this I found out we only support 7-bit I2C addresses. I'll come back and fix that later.
0f69060
to
87b286e
Compare
Interesting problem. The root cause is that the type can be used in two different contexts, and it depends on the context whether the caller wants the async or the blocking methods. This can't be disambiguated on the type itself. What are the options?
|
Sounds about right. Can't think of anything else. |
Always using the trait doesn't really solve the problem either if you have both sync and async traits in scope. You still need to disambiguate. For inherent methods, I'd probably affix (pre- or su-) the method colour to its name. I don't like call-site disambiguation as, to some extent, it defeats the point of traits and type inference. I really don't like how it breaks the UX of async code :( |
Is this really an issue? Why would you import both the sync and the async traits? If it's a rare situation, then manual disambiguation is fine IMHO. If most users of the async traits would need to import the sync ones as well, I'd say that would be a limitation of the async traits and they should be improved so it's no longer needed.
That's an option, but I wonder if it provides better usability compared to just using the traits. I guess it provides better discoverability? |
Indeed, The only case where I’d expect to see both traits in scope is in the HiL tests and even there I managed to work around that problem.
Yeah, my affix suggestion is for if we really want to have inherent methods. |
I was more worried about disoverability when reading the docs. I could go for inherent |
Also we have inherent methods, so you can ignore the Embedded HAL traits if you want (makes the examples simpler too).
Whilst doing this I found out we only support 7-bit I2C addresses. I'll come back and fix that later.