-
Notifications
You must be signed in to change notification settings - Fork 11
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
Removing ownership of menu context #18
Conversation
Ah, clever. Will this be a breaking change for existing menus? |
Indeed this is a very breaking change and can be annoying for the end user to update because all of the APIs for callbacks change as a result. I've updated the example and added a CHANGELOG for this. I'm wondering if now also makes sense to update to using the |
Could the owned |
The |
That being said, We could update this so that the |
If the Context supported embedded-io, you wouldn't need to pass bytes - you'd just call |
I suspect this may be the cleanest implementation. Let me take a look at what that would look like. Thanks for the feedback! |
In our case we'd probably construct a throw-away |
No, that also wouldn't work because the In our case, we would have to move the ownership of our |
If you have a diff for a project that uses this crate, that would need very interesting to see |
@thejpster Check out https://github.com/quartiq/stabilizer/pull/872/files#diff-f0b20facc8d3d2dfccda7199e70cb8af5ba9255d80e1d35fdd950dc6a2d567a3 - we are using menu in a separate crate |
Looks good to me. Do you want to merge this as-is, add look at those other changes later? |
Let me take a look at what the refactor would be tomorrow and how it looks for the end user :) I suspect it could simplify things |
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 like this - just a few notes.
src/lib.rs
Outdated
#[cfg(feature = "echo")] | ||
{ | ||
// We have to do this song and dance because `self.prompt()` needs | ||
// a mutable reference to self, and we can't have that while |
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.
Is this still true now context is passed out of band?
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 this is still true because of borrowing self.buffer
for the string and then mutably borrowing self
when calling self.prompt()
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.
ahh
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.
but can prompt be made non-mut?
While this newer approach is nicer internally to |
I'm not sure why it's different in that regard to how it was. The main benefit here seems to be that the caller can own the context and the runner separately, and bring them together when there are characters to process. |
It's not different w.r.t the released version of menu, but it is somewhat different w.r.t 7ba8849. Specifically, the issue is as follows:
What this means is that we now have to wrap our The root of the issue ultimately is the anonymous lifetime borrow. Whatever the |
So you'd prefer two objects: one interface object and one context object? Could you use a tuple of them both as a single context? |
I'm not sure if this is an issue that other users will face or one that arises out of our firmware architecture honestly, so I'm not sure if I know the "right" way.
This is the root of the problem. This would make the context have a type of My gut reaction is that it might make more sense to have separate Interface and Context items, but I'm not 100% sure that's the right design for everyone. |
But if you pass a value of that type to the Runner's input _bytes method, who needs to know the type? |
The problem is that we have the |
@thejpster In all honesty, I don't know what the right path is. Given that, I'd say we leave this as-implemented in this PR and move forward and see how it goes. We can always come back to it later. If things look good to you, feel free to re-approve/merge as appropriate :) Thanks for the review! |
@ryan-summers Didn't we have the the impression that combining interface and context was cumbersome for applications, and that 7ba8849 (plus picking the e-io updates) was better (despite the two type parameters)? |
Yes, but I'm not convinced that's true for the general use case of this library or not. Two type parameters is more flexible, but it does make the library slightly more complex to use as well. I'm somewhat ambivalent as to what the right approach is personally given that our only test case is currently stabilizer. |
I now regret having floated the idea ;) |
The more I think about it, the more @jordens is convincing me that we should revert to 7ba8849, specifically because that the If we combine |
Should the runner own the interface or should it have a |
My opinion here is that the interface is much more closely tied to I would imagine that it is rarer for the user to want to use the I'm not opposed to the idea, but I would recommend we do that in potentially a follow-on PR instead |
Thank you for the changes and the thoughtful discussion! It is greatly appreciated. |
This PR fixes #17 by updating the
Context
to no longer be owned by theRunner
. Instead, aninterface
is owned (to handle I/O) and the context is borrowed to the runner when IO is being processed.