std::ops::Fn
Trait std::ops::Fn
#[lang = "fn"] pub trait Fn<Args>: FnMut<Args> { extern "rust-call" fn call(&self, args: Args) -> Self::Output; }
A version of the call operator that takes an immutable receiver.
Examples
Closures automatically implement this trait, which allows them to be invoked. Note, however, that Fn
takes an immutable reference to any captured variables. To take a mutable capture, implement FnMut
, and to consume the capture, implement FnOnce
.
let square = |x| x * x; assert_eq!(square(5), 25);
Closures can also be passed to higher-level functions through a Fn
parameter (or a FnMut
or FnOnce
parameter, which are supertraits of