I would like to pass the options of my CLI program via a Config
-struct that has ownership of its values, i.e. String
s 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?
Asked
Active
Viewed 303 times
0

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 Answers
2
ArgMatches::remove_many
will give you ownership, by moving those values out of the ArgMatches
struct.

PitaJ
- 12,969
- 6
- 36
- 55