In a blog post, Rust contributor withoutboats mentions:
Most of my functions with many return paths terminate with a
match
statement. Technically, these could be reduced to a single return path by just wrapping the whole match in anOk
, but I don’t know anyone who considers that good form, and I certainly don’t.
一个(有些人为的)例子
坏:
Ok(match response {
UserResponse(user) => user,
ItemResponse(item) => item?,
})
更好:
match response {
UserResponse(user) => Ok(user),
ItemResponse(item) => Ok(item?),
}
为什么会这样?