How do I expose an imported trait from the struct that derives it?

40 Views Asked by At

I have a file called my_args.rs and it goes something like this.

use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about)]
struct MyArgs(){
...
}

and in main.rs

use crate::my_args::MyArgs;

pub fn main(){
// parse args
let args = MyArgs::parse();
}

I get a compilation error that tells me I should add "use clap::Parser;" to my main.rs too.

It worked when I followed its suggestion.

But what about if I wanted to ship MyArgs to be used by other people, how are they supposed to know that it is a clap parser?

Is there a way I can exposed the derived Parser trait through the struct that derives it?

0

There are 0 best solutions below