Fn is implemented automatically by closures which only take immutable
references to captured variables or don’t capture anything at all, as well
as (safe) function pointers (with some caveats, see their documentation
for more details). Additionally, for any type F that implements Fn, &F
implements Fn, too.
Since both FnMut and FnOnce are supertraits of Fn, any
instance of Fn can be used as a parameter where a FnMut or FnOnce
is expected.
Use Fn as a bound when you want to accept a parameter of function-like
type and need to call it repeatedly and without mutating state (e.g., when
calling it concurrently). If you do not need such strict requirements, use
FnMut or FnOnce as bounds.
Also of note is the special syntax for Fn traits (e.g.
Fn(usize, bool) -> usize). Those interested in the technical details of
this can refer to the relevant section in the Rustonomicon.
Convert the provided type (generally a closure) to Self (generally a “children” type,
e.g., Children). See the implementations to see exactly which input types are supported
and which “children” type they are converted to.
Convert the provided type (generally a closure) to Self (generally a “children” type,
e.g., Children). See the implementations to see exactly which input types are supported
and which “children” type they are converted to.