this post was submitted on 22 Jun 2023
6 points (100.0% liked)

Rust

6049 readers
67 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

I've tried to run the example under "Configuring the Parser" and get some errors. What could be my problem?

Errors

  • error: cannot find derive macro Parser in this scope
  • error: cannot find attribute command in this scope
  • error: cannot find attribute arg in this scope
  • error[E0599]: no function or associated item named parse found for struct Cli in the current scope

Cargo.toml

[package]
name = "hello_cargo"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = "4.3.5"
you are viewing a single comment's thread
view the rest of the comments
[โ€“] kirsten 1 points 1 year ago* (last edited 1 year ago) (1 children)

Thanks a lot. That's it. But, what have I done now ๐Ÿ˜€ ? I believe I misunderstand the dependency inclusion. I have to learn something about features and why they aren't activated by default.

[โ€“] snaggen 4 points 1 year ago (1 children)

a crate may contain may different parts, and you may not always want all of them to avoid bloat. For an example, a crate may contain a sync and an async version, but you will probably only want one of them. So then the crate exposes the different parts as features. In clap they have defined the default features as:

default = ["std", "color", "help", "usage", "error-context", "suggestions"]

So, then if you need to use functionality not included there, then you have to specify it in your features list. On https://docs.rs/crate/clap/latest you can find a drop down in the top menu with Feature Flags, then they also have the documentation for the feature flags here https://docs.rs/clap/latest/clap/_features/index.html

[โ€“] kirsten 1 points 1 year ago

That was really helpful, thanks.