forked from oconnor663/duct.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support optional arguments and sequences in cmd!
This commit allows the cmd! macro to also splice in any sequence which implements IntoIterator<Item: Into<OsString>>. This requires a bit of extra syntax in the cmd! macro since it would be possible for a type to implement both Into<OsString> and IntoIterator. So, in order to pass in a sequence to cmd! it needs to be prefixed with ... like this: cmd!("echo", "a", ...sequence, "b"); I have chosen ... here because ...<expr> is not a valid rust expression and so it shouldn't conflict with anything else. Unfortunately, it's not really possible to cleanly create a macro input which declaratively parses either ...$arg or $arg so the cmd! macro just takes a bunch of tokens and uses a second helper macro (cmd_expand_args!) in order to parse that into something usable. Since Option also implements IntoIterator this can also be rather easily used for optional arguments since you can just do: cmd!("echo", "a", ...Some("b")); I have tried to expand the docs with some examples to cover all of these use cases which should cover for the actual macro arguments shown in rustdoc being less readable now. Fixes oconnor663#88
- Loading branch information
Showing
2 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters