Skip to content
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

range method not found in _AnonymousValueParser(usize) #4253

Open
2 tasks done
pkolaczk opened this issue Sep 24, 2022 · 5 comments
Open
2 tasks done

range method not found in _AnonymousValueParser(usize) #4253

pkolaczk opened this issue Sep 24, 2022 · 5 comments
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@pkolaczk
Copy link

Please complete the following tasks

Rust Version

rustc 1.64.0 (a55dd71d5 2022-09-19)

Clap Version

4.0.0-rc2

Minimal reproducible code

#[derive(clap::Parser, Debug, Default)]
#[command(disable_version_flag = true)]
struct MyApp {
    #[arg(value_parser = clap::value_parser!(usize).range(1..))]
    pub foo: Option<usize>
}

fn main() {
}

Steps to reproduce the bug with the above code

cargo check

Actual Behaviour

error[E0599]: no method named `range` found for struct `_AnonymousValueParser` in the current scope
 --> src/test.rs:4:53
  |
4 |     #[arg(value_parser = clap::value_parser!(usize).range(1..))]
  |                                                     ^^^^^ method not found in `_AnonymousValueParser`

Expected Behaviour

Should compile fine

Additional Context

If I replace the usize type in value_parser! with u64, then it compiles fine, however I'm not sure if this is correct, because that's a different type than the type used in the field.

Debug Output

No response

@pkolaczk pkolaczk added the C-bug Category: Updating dependencies label Sep 24, 2022
@anshulrgoyal
Copy link

@pkolaczk clap::value_parser! returns RangedU64ValueParser for u64 therefore range function is available, but usize returns _AnonymousValueParser hence the compilation error.

If there is an implementation for usize then it will work.

impl ValueParserFactory for usize {
    type Parser = RangedU64ValueParser<usize>;
    fn value_parser() -> Self::Parser {
        RangedU64ValueParser::<usize>::new()
    }
}

@pkolaczk
Copy link
Author

Such implementation can be added only by clap. I cannot add it by myself, because of foreign-crate restriction.

@anshulrgoyal
Copy link

@pkolaczk I was suggesting adding the implementation in clap only. I don't know the reason it is not already present.

@epage
Copy link
Member

epage commented Sep 26, 2022

I wish I could more generically implement this...

clap does use try_into to go from u64 to T (usize in this case). My main question is if converting from u64 to usize is "good enough" or if we should have usize-native value parser.

@epage epage added S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing A-builder Area: Builder API labels Sep 26, 2022
@epage
Copy link
Member

epage commented Sep 28, 2022

btw #3895 and #4034 are related PRs

@epage epage changed the title range method not found in _AnonymousValueParser range method not found in _AnonymousValueParser(usize) Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-bug Category: Updating dependencies S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

3 participants