by earenndil · 8y ago · 0 comments
AFAIK (not too familiar with rust or c++), you can do something like this:
if (Maybe may = whatever; may.issome) if let Some(x) = y {
println!("y has a value, {}", x);
}
Whereas with a method, the contents of the variant are not bound: if y.is_some() {
println!("y has a value, {}", /* uh… */);
}
In Rust, pattern matching is the only to get at the contents of an enum. Methods like is_some() are just this: pub fn is_some(&self) -> bool {
match *self {
Some(_) => true,
None => false,
}
}