3 ms·
If anyone wondering what that means for "optional ifs": if let Some(new_variable) = method_that_returns_optional_value { println!("value: {
by kmarc 3y ago
If anyone wondering what that means for "optional ifs":
if let Some(new_variable) = method_that_returns_optional_value {
println!("value: {new_variable}")
} else {
println!("{new_variable} is not in scope, this wont't compile");
}
I find it powerful. "if-let" and "while-let" are part of the language. OTOH rustaceans are happy with and constantly reasoning (constantly fighting the borrowchecker?) about scopes and if a variable / it's intended value is accessible at a certain line of the source code.