Consider the following snippet:
use std::fmt;
enum TestEnum {
StructMem {value: i32, is_valid: bool},
RandoMem,
}
impl fmt::Display for TestEnum {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TestEnum::*;
match self {
StructMem {value, is_valid} => {
if *is_valid { // Why dereference is_valid ?
write!(f, "f")?
}
write!(f, "{:?}", value)
}
RandoMem => {
f.write_str("Random")
}
}
}
}
Why do I need to dereference is_valid
in the if
statement?
EDIT: This question What is the syntax to match on a reference to an enum? seems to be dealing with a similar situation, but the answers are all focused on solving the specific issue (which does not involve a struct) and are not explaining the ownership/binding semantics.