# Trait ethcore_util::standard::ops::Fn 1.0.0 [−] [src]

    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 `Fn`).

    fn call_with_one<F>(func: F) -> usize
        where F: Fn(usize) -> usize {
        func(1)
    }

    let double = |x| x * 2;
    assert_eq!(call_with_one(double), 2);

## Required Methods

### `extern "rust-call" fn call(&self, args: Args) -> Self::Output`

Unstable (`fn_traits`)

This is called when the call operator is used.

## Implementors

- `impl<'a, A, F> Fn<A> for &'a F where F: Fn<A> + ?Sized`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)