Comment on Rust vs Go: A Hands-On ComparisonparentComments−Yoric2yFor 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.
Comments
For what it's worth, in Rust, this pretty much translates to
or, in most cases, the shorter If you forgot to call `with_context` and simply write 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.