logoalt Hacker News

loegyesterday at 11:11 PM2 repliesview on HN

  let mut file = File::create("foo.txt").context("failed to create file")?;
Of all the things I find hard to understand in Rust, this isn't one of them.

Replies

snuxollyesterday at 11:24 PM

Important to note that .context() is something from `anyhow`, not part of the stdlib.

fragmedetoday at 12:56 AM

What's the "?" doing? Why doesn't it compile without it? It's there to shortcut using match and handling errors and using unwrap, which makes sense if you know Rust, but the verbosity of go is its strength, not a weakness. My belief is that it makes things easier to reason about outside of the trivial example here.

show 2 replies