In Scala, I can use getOrElse as a convenient way to get a default value from Option, what's the equivalent of this in Rust?
val threeOpt = Some(3)
val shouldBeThree = threeOpt.getOrElse(-1) // got 3
You can use either unwrap_or or unwrap_or_else
unwrap_or is eagerly evaluatedunwrap_or_else is lazily evaluatedSee here for differences between eager and lazy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With