Is there any better ways to match on a string from standard input?

Currently I am using match to classify the string from standard input.
It's okay now because there are only four cases, but if there are more cases, it'll get too messy. Is there a better way?

match command {
			"Hello" => {
				println!("Hello");
			}
			"US" => {
				println!("US");
			}
			"Rust" => {
				println!("Rust");
			}
			"Python" => {
				println!("Python");
			}
			_ => {
				println!("Print something");
			}
		}

For that question to answerable you need to define what “better” even mean. You can use maplit to create a map literal and map strings. You can use "C" | "C++" | "Rust => "Low-leve languages" match syntax.

And there are many other potential “improvements”. But before you consider these you should answer to yourself what's exactly wrong with the code which you wrote.

3 Likes