rust - Mismatched types on matching string -
i seem mixing types can't quite figure out how fix this. can me?
let args_vector: vec<string> = env::args().collect(); arg in &args_vector[1..]{ match arg{ "--bytes" => { flag.c = true; }, "--chars" => { flag.m =true; }, _ => println! ("error"), } }
on matches, i'm getting error:
mismatched types: expected struct `std::string::string`, found str
here arg of type string
in match , "--bytes"
of type &str
. arg
of type string
has converted &str
. can done using string::as_ref()
.
let args_vector: vec<string> = env::args().collect(); arg in &args_vector[1..] { match arg.as_ref() { "--bytes" => { flag.c = true; } "--chars" => { flag.m = true; } _ => println!("error") }; }
note missing ;
after println!
make match
arms return same type.
Comments
Post a Comment