Rust tips @rust@octodon.social
Follow

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