Rust中Scala的getOrElse相当于什么?

Ren*_*kai -6 optional rust

在Scala中,我可以getOrElse方便地从中获取默认值Option,Rust中的等效值是什么?

val threeOpt = Some(3)
val shouldBeThree = threeOpt.getOrElse(-1) // got 3
Run Code Online (Sandbox Code Playgroud)

Sha*_*tri 6

您可以使用unwrap_orunwrap_or_else

  • unwrap_or 渴望评估
  • unwrap_or_else 懒惰地评估