I am trying to use a match
with user inputs from the command line to create a simple interface for a program.
Here is the relevant code:
let NEW_BLOCK: String = String::from("NEW_BLOCK");
let ADD_BLOCK: String = String::from("ADD_BLOCK");
let PRINT_CHAIN: String = String::from("PRINT_CHAIN");
let PUBLISH: String = String::from("PUBLISH");
let input = String::from("some input");
match input {
NEW_BLOCK => {
println!("inside NEW_BLOCK");
},
ADD_BLOCK => {
println!("inside ADD_BLOCK");
},
PRINT_CHAIN => {
println!("inside PRINT_CHAIN");
},
PUBLISH => {
println!("inside PUBLISH");
},
_ => {
println!("Inside else");
},
}
This produces a few warnings such as:
warning: unreachable pattern
--> src/main.rs:13:9
|
10 | NEW_BLOCK => {
| --------- matches any value
...
13 | ADD_BLOCK => {
| ^^^^^^^^^ unreachable pattern
|
= note: `#[warn(unreachable_patterns)]` on by default
No matter the value of input
, I always go into the NEW_BLOCK
arm. In general, I always go into the first arm of the match
operator. I don't know why.
My best guess is that the comparison that match
is using is only comparing the types. But I don't think this is a very good guess.
Does anyone know why this is happening? Thank you in advance for the help :)
(By the way, a found workaround using string slices. However, I'd like to know why using Strings isn't working).