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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -