Rust tips is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Rust tips @rust

In functions returning `Result` you can avoid repeating `Ok()` all the time by moving it to the outermost scope.

Instead of:

match foo {
bar => Ok(1)
baz => Ok(2)
quz => Ok(3)
_ => Err("etc"),
}

use:

Ok(match foo {
bar => 1,
baz => 2,
quz => 3,
_ => Err("etc")?,
})

· Web · 0 · 1