Hacker News new | past | comments | ask | show | jobs | submit login

Rust has many convenient shorthands like the ? operator, where `let x = foo()?` is equivalent to

  let x = match foo() {
      Ok(value) -> value,
      Err(e) -> return Err(e),
  }



IIRC, `let x = foo()?` is actually equivalent to

  let x = match foo() {
      Ok(value) -> value,
      Err(e) -> return Err(e.into()),
  }
Which can automatically convert one error type into another when the appropriate From and/or Into impls exist.


It is a little more complex than that these days

https://github.com/rust-lang/rust/blob/4e0d0d757e2f1b61ec809...


Many convenient shorthands that you all have to be familiar with before being able to write (and read) Rust competently. I guess that's what they mean with the steep learning curve...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: