How to infer the return type of a function? [duplicate]
问题 This question already has an answer here : Differences in Type inference for closures and functions in rust (1 answer) Closed 2 years ago . The return type of a block is inferred. fn main() { let x = { 5 }; println!("{}", x); } But when I give the block a name, I have to specify a type. fn five() -> i32 { 5 } fn main() { let x = five(); println!("{}", x); } How can I avoid selecting a type? 回答1: You cannot. Rust explicitly prohibits this by design. However, for large and complex return types,