News for hackers. Stuff that matters.
Re:Rust: A Critical Retrospective by veber-alex on Thursday May 19, 2022 @11:23AM (#31435895)
I don't see how that is all that different from Rust.

The main difference I see is that in Rust it will also work with your own custom types, not just optional.

  fn make_bla() -> Option<Bla> {
    // this either returns a valid Bla, or None
  }

  if let Some(bla) = make_bla() {
    // bla is now the unwrapped valid type
  } else {
    // make_bla() returned None
  }
..or with the '?' operator (early return)

  let bla = make_bla().ok_or(InvalidBla)?;
..or with let_else (nightly only but should be stable Soon(tm))

  let Some(bla) = make_bla() else { return Err(InvalidBla) }
..or panic on None

  let bla = make_bla().unwrap();

There are no comments on this comment yet.