But == is not if. if processes bools, not arbitrary comparisons. The way you can rewrite an if to match is:
match a == "hello" {
true => println!("if = {}", a),
false => {},
}
This is still not quite the same, because the match will accept &bool whereas if will not, but it's very similar. “Is syntactic sugar for” is an exaggeration, but they are very similar.
PartialEq trait implementations, not deref coercions.
Your wording is a bit unprecise. First of all, your code still doesn't compile because the types still don't match (pun not intended). You need to take a slice from the original string to make it work
fn main() {
let a = String::from("hello");
match &a[..] {
"hello" => println!("match = {}", a),
_ => ()
}
}
See the &a[..] expression which has type &str like the match arms.
Second, the _ pattern does not stand for "undefined" but is a so called wildcard. It basically means "match anything". The reason you need this wildcard here is because match statements are exhaustive. That means that the match arms need to cover every possible value of type &str. Because &str is variable length there are infinetely many possible values for the type &str. Therefore, you need a default match arm that applies if all other match arms failed to match. And in this case, that's the _ pattern.