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
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 evaluated