3 ms·
Is it? It does something with y if it is something, otherwise it does nothing...
by earenndil 8y ago
Is it? It does something with y if it is something, otherwise it does nothing...
- chrismorgan 8y agoTo make clearer what I meant by pattern bindings being available: 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, } }