What enables a function trait type (std::ops::Fn
) to be used where an fn type (e.g. closure, function definition, fn
pointer type) is expected?
fn take_closure<F: Fn(u32) -> u32>(_f: F) {}
fn id(x: u32) -> u32 {
x
}
fn main() {
take_closure(id);
}
Is it:
- an impl of
Fn
for each correspondingfn
type? - or a coercion, like the the one from
Fn
tofn
I'm asking more about mental model than about concrete implementation.
Edit
updated the example, previously the example showed conversion the other way. Sorry about that. I created a separate question to ask about conversion the other way: What enables a closure type to be used where a function pointer type to be used in Rust?