clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.25k stars 1.04k forks source link

Support parsing smart pointers #4989

Open KSXGitHub opened 1 year ago

KSXGitHub commented 1 year ago

Please complete the following tasks

Clap Version

4.3.8

Describe your use case

Box of an unsized type is often smaller than its owned counterpart. And it is cheaper to clone Rc and Arc than cloning the owned version.

Describe the solution you'd like

Allow parsing arguments directly to smart pointer types such as Box, Rc, and Arc. For example:

#[derive(Clone, Parser)]
struct Args {
    #[clap(long, short)]
    tag: Arc<[Box<str>]>, // instead of Vec<String>
    files: Arc<[Box<Path>]>, // instead of Vec<PathBuf>
}

Alternatives, if applicable

No response

Additional Context

No response

epage commented 1 year ago

4626 is a more general re-evaluation of how we infer meaning from types