Is there a way to compare a variable of type String with a variable of type &str. I know I can convert the latter to String but I don't want to do that. The code goes as follows:
mod print;
use std::env;
use commons::{error, help};
fn match_arg(args: &[String]) {
let util = &args[0];
match *util {
"print" => print::main(args),
}
}
fn main() {
let args: Vec<String> = env::args().collect();
// Skip the name of the program
let args = &args[1..args.len()];
match_arg(args);
}
If I try to convert the value in the match arm to a String, it will tell me that we cannot execute function calls inside a match arm. So I can do it with an if but I wondering if it's possible without converting it to an &str. Also I didn't said that but I'm just starting out with Rust so maybe there is another way to do what I try to do?
Thanks a lot! I will of course handle the case I have no arguments but that was some pseudocode-like code to just demonstrate the problem. Have an amazing day and thanks for the help!