4 ms·
pub functions: should be explicit module functions: if I chose, I'd let them be derived, but I'm relatively indifferent inner functions: should be allowed to
by bryanlarsen 4y ago
pub functions: should be explicit
module functions: if I chose, I'd let them be derived, but I'm relatively indifferent
inner functions: should be allowed to be derived, IMO. They're very infrequently used so this choice doesn't have much impact.
- nicoburns 4y agoYou can use closures as functions with type inferred signatures
- bryanlarsen 4y agoClosures capture variables so have significant differences compared to inner functions. Capture can affect lifetimes so the difference is significant in Rust.
- nicoburns 4y agoClosures don't have to capture variables. If they don't then they're equivalent to functions.
- bryanlarsen 4y agoThat's what I thought too, but I fixed some compiler errors by turning a closure into an inner function. Probably a PBKAC, but...
- LegionMammal978 4y agoPerhaps it's due to the fact that you can't really have type-generic closures in Rust: once the compiler has inferred one type, the closure cannot be used with another type. In contrast, inner functions can have any number of additional type parameters.