use clap::{App, Arg, ArgMatches};
use std::path::PathBuf;
struct CmpOptions {
file1: PathBuf,
file2: Option<PathBuf>,
}
impl CmpOptions {
fn new(matches: ArgMatches) -> Self {
Self {
file1: matches.value_of("file1").unwrap().into(),
file2: matches.value_of("file2"),
}
}
}
fn main() {
println!("Hello");
}
fn parse_command_line() -> CmpOptions {
let matches = App::new("cmpr")
.arg(
Arg::with_name("file1")
.required(true)
.index(1),
)
.arg(
Arg::with_name("file2")
.index(2),
)
.get_matches();
CmpOptions::new(matches)
}
13 | file2: matches.value_of("file2"),
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `PathBuf`, found `&str`
|
= note: expected enum `Option<PathBuf>`
found enum `Option<&str>`
How can I convert from Option<&str> to Option please?
Thanks.