Remove one shot commands.#959
Remove one shot commands.#959luleyleo merged 7 commits intolinebender:masterfrom luleyleo:remove-one-shot-commands
Conversation
cmyr
left a comment
There was a problem hiding this comment.
Cool yea I think this is an improvement. A few comments inline, but looks good!
| /// `SingleUse` is intended for cases where a command payload should only be | ||
| /// used once; an example would be if you have some resource that cannot be | ||
| /// cloned, and you wish to send it to another widget. | ||
| pub struct SingleUse<T>(Mutex<Option<T>>); |
There was a problem hiding this comment.
this type isn's actually exposed anywhere, so I don't think external crates can access it?
Also I would expect this to need to be in an Arc, since the Event itself still needs to be cloneable?
There was a problem hiding this comment.
Good catch, I've reexported it from lib now.
Not sure what you mean regarding the Arc. When using SingleUse the payload will be stored the exact same way as it used to with Arg::OneShot, minus the Box<Any> wrapper as it is now directly stored as Arc<Any>.
There was a problem hiding this comment.
ah okay I missed that the Arc has moved into the signature of the object field on Command.
druid/src/command.rs
Outdated
| Reusable(Arc<dyn Any>), | ||
| OneShot(Arc<Mutex<Option<Box<dyn Any>>>>), | ||
| } | ||
| /// `SingleUse` is intended for cases where a command payload should only be |
There was a problem hiding this comment.
huh I think I lost a comment here?? anyway, to try again:
Doc comments are kind of like git commit messages; you want the first paragraph to be a short general overview that doesn't need a lot of context, and then a blank line, and then a more detailed explanation.
This is because the first paragraph is displayed beside the type name in the module or crate level docs.
For this type, for instance, I would try a first paragraph of something to the effect of,
"A wrapper type for Command arguments that should only be used once."
There was a problem hiding this comment.
Thanks, I should have actually built the docs 😅
I've added the suggested head paragraph, and while I was at it also an example how to make use of SingleUse.
cmyr
left a comment
There was a problem hiding this comment.
One little non-blocker, thanks for this!
Fourth part of #908 .
I gave the suggestion by @cmyr a try and replaced one shot commands with a
SingleUsewrapper type and it seems to work really well.To summarize the change:
is now
which can easily be utilized by typed selectors.