-
I'd like to be able to write in a style as close as possible to a table similar to the one
I'd like to write pub fn options() -> OptionParser<Options> {
let switch = s('s').l("switch" ).h("Switch with many names").switch();
let arg = s('a').l("also-arg").h("Argument with names" ).argument::<usize >("ARG");
let username = s('u').l("user" ).h("Custom user name" );
// when options have extra combinators that wouldn't fit in this table, they can be added later ↓
let username = username.env("USER1").argument::<String>("USER");
construct!(Options {switch,arg,username}).to_options()
} I managed to shorten the first |
Beta Was this translation helpful? Give feedback.
Answered by
pacak
Jul 30, 2023
Replies: 1 comment 5 replies
-
You can make a wrapper type or a wrapper trait for pub trait ShortName {
fn s(self, name: char) -> NamedArg {
self.short(name)
}
...
}
impl ShortName for NamedArg {} |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
eugenesvk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can make a wrapper type or a wrapper trait for
NamedArg
that would translate your short names to long ones, something like this: