`demo.rs` does not compile on its own
DeflateAwning opened this issue · comments
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Rust Version
rustc 1.77.0 (aedd173a2 2024-03-17)
Clap Version
clap = "4.5.4"
Minimal reproducible code
Copied directly from: https://github.com/clap-rs/clap/blob/9d14f394ba22f65f8957310a03ae5fd613f89d76/examples/demo.rs
use clap::Parser;
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Name of the person to greet
#[arg(short, long)]
name: String,
/// Number of times to greet
#[arg(short, long, default_value_t = 1)]
count: u8,
}
fn main() {
let args = Args::parse();
for _ in 0..args.count {
println!("Hello {}!", args.name)
}
}
Steps to reproduce the bug with the above code
Run the code.
Actual Behaviour
It has a bunch of compile errors.
Expected Behaviour
I'd expect a file named demo.rs
to work in isolation.
Additional Context
Disclaimer: I don't really know what I'm doing. I'm sure someone who knew what they were doing would have more success than I am.
Debug Output
No response
Generally, the examples are written to be viewed from rustdoc. For example, see https://docs.rs/clap/latest/clap/#example for the discussion on demo.rs
If you want to bypass that, to understand examples, you need to look at the context of the Cargo.toml
. See
Lines 117 to 119 in 9d14f39
As this is working as expected and people do have a path forward, I'm going to go ahead and close this. If there is a reason for us to reconsider, let us know!
Could you please consider adding a README to that folder which directs people to the docs appropriately?
Ah I do remember reading that, and didn't get the impression that the examples weren't meant to function in isolation.
Perhaps a message along the lines of the following would be beneficial:
These examples are not meant to function in isolation, and are only suplemental material to the following tutorial(s):