-
Notifications
You must be signed in to change notification settings - Fork 4
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
Provide explicit getters for inner sync objects. #7
Comments
BTW, if this is OK, I can put up a PR, unless there's a better/easier way to do it. |
Unraveling nesting can be a pain, but adding functions to skip over it is at least as confusing to me.
That approach is clearer to me, as it highlights which request calls are synchronous. |
Yeah, that would work, but it doesn’t seem like a clean/easy API. I’m agnostic to the naming for a get function; maybe My assumption in this is that since the async wrapper only exposes a few of the event reader functions it will likely be common for users to access the inner object to get to the rest of the functionality of them. |
I suppose the other option is to fill out the API of the asynchronous objects with the synchronous calls as well. Or at least the more common ones. In that way, users needing to go to the inner objects would be less common. Like
I effectively did something like this in socketcan-rs by making a trait for synchronous functions built on top of
Then the individual structs, both synchronous and async just implement the empty trait and get all the functions.
So these didn't implement the read/write functions which have different signatures in the different versions... just the common calls that are always synchronous (in this case wrapping the iotl calls to get/set socket options). I actually would have never thought of this, but someone sent in a PR with that done for the two different synchronous socket types, and I just extended it for the async ones as well. |
Seems idiomatic to me.
Don't like
For sure - the bulk of the API is synchronous. And I prefer keeping it clear that it is. Hiding things is not always a good thing.
Did that for gpiosim, with the But, back to the point, I don't like doing that here, as it implies that the functions added to the So I prefer keeping the sync and async APIs distinct. Then if we do ever want to add async versions we can. TL;DR |
Yeah, I agree, just providing the accessor seems the best way to go. (Ditto for And I agree that since the word "request" is a verb and a noun, it adds some potential for confusion. But I stick with my original suggestion. Really, who can complain about a function named But whatever you decide is fine. |
That would be me :-D. I'm just as happy with |
This is another usability nit.
When using the asynchronous objects, like
tokio::AsyncRequest
, it you put them behind a pointer like anArc
, it becomes difficult to access the underlying synchronous object throughget_ref()
since the pointer itself implementsAsRef
.Like:
If you do
req.as_ref()
, you get the reference of the pointer, and thus an&AsyncRequest
, and not a&Request
as you might have expected. To get to theRequest
you need to dereference the ponter, like:That works, but is a little confusing and gets more difficult if the
req
pointer is buried in a struct.It might be nice to add an explicit call to get the underlying reference, perhaps like:
Then you can just do:
Ditto for
AsyncChip
.The text was updated successfully, but these errors were encountered: