0

I would like to pass the options of my CLI program via a Config-struct that has ownership of its values, i.e. Strings of paths. The now deprecated ArgMatches::values_of_lossy() returned an owned String, however, ArgMatches::get_many() only returns a ValuesRef<>. What is the best way to get ownership of the argument itself, ideally without cloning?

s1gsegv
  • 77
  • 3
  • 2
    [`ArgMatches::remove_many`](https://docs.rs/clap/latest/clap/struct.ArgMatches.html#method.remove_many) will give you ownership, by moving those values out of the `ArgMatches` struct. – PitaJ Aug 04 '22 at 19:05
  • You may want to consider using the [`derive` feature](https://docs.rs/clap/latest/clap/_derive/index.html) if you have a struct you want to parse into. – PitaJ Aug 04 '22 at 19:09

1 Answers1

2

ArgMatches::remove_many will give you ownership, by moving those values out of the ArgMatches struct.

PitaJ
  • 12,969
  • 6
  • 36
  • 55