use unwrap_or to get default value
This commit is contained in:
+3
-1
@@ -8,5 +8,7 @@ fn add_10(value: Option<u32>) -> Result<u32, String> {
|
||||
fn main() {
|
||||
let value = add_10(None);
|
||||
|
||||
println!("Result is: {}", value.unwrap());
|
||||
println!("Result is: {}", value.unwrap_or(42));
|
||||
|
||||
panic!("Non recoverable error.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user