News for hackers. Stuff that matters.
Re:Rust vs Go: A Hands-On Comparison by Yoric on Wednesday September 27, 2023 @02:25PM (#37678982)
For what it's worth, in Rust, this pretty much translates to

   some_operation(&arg)
      .with_context(|| format!("Some operation failed: {arg}"))?;
or, in most cases, the shorter

   some_operation(&arg)
      .context("Some operation failed")?;
If you forgot to call `with_context` and simply write

   some_operation(&arg)?;
the error is still propagated, it's just missing whatever context you wanted to add.

Whether that's better or worse than the Go snippet is something I'll let the reader decide.

There are no comments on this comment yet.