-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
ArgValue derive #2762
ArgValue derive #2762
Changes from all commits
b589a6c
88d7d02
d3f0534
f002cdc
76f7211
ac1a9d6
480035a
15fcf81
d53778e
47ff3ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,11 +76,13 @@ pub fn args(name: &Ident) { | |
pub fn arg_enum(name: &Ident) { | ||
append_dummy(quote! { | ||
impl clap::ArgEnum for #name { | ||
const VARIANTS: &'static [&'static str] = &[]; | ||
fn value_variants<'a>() -> &'a [Self]{ | ||
unimplemented!() | ||
} | ||
fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> { | ||
unimplemented!() | ||
} | ||
fn as_arg(&self) -> Option<&'static str> { | ||
fn arg_value<'a>(&self) -> Option<clap::ArgValue<'a>>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about naming this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call might allocate (for aliases) and so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed it to |
||
unimplemented!() | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
use clap::ArgEnum; | ||
|
||
#[derive(ArgEnum, Debug)] | ||
#[derive(ArgEnum, Clone, Debug)] | ||
struct Opt {} | ||
|
||
fn main() { | ||
println!("{:?}", Opt::VARIANTS); | ||
println!("{:?}", Opt::value_variants()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
error: `#[derive(ArgEnum)]` only supports enums | ||
--> $DIR/arg_enum_on_struct.rs:3:10 | ||
| | ||
3 | #[derive(ArgEnum, Debug)] | ||
3 | #[derive(ArgEnum, Clone, Debug)] | ||
| ^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `ArgEnum` (in Nightly builds, run with -Z macro-backtrace for more info) |
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.
Once the trait method is renamed