The version of the call operator that takes a by-value receiver. Instances of FnOnce can be called, but might not be callable multiple times. Because of this, if the only thing known about a type is that it implements FnOnce, it can only be called once. FnOnce is implemented automatically by closures that might consume captured variables.

Signature

pub trait FnOnce

Examples

fn consume_with_relish, +core::ops::FnOnce[Output: O], +core::fmt::Display, +Drop,
>(
    func: F,
) {
    // `func` consumes its captured variables, so it cannot be run more
    // than once.
    println!("Consumed: {}", func());

    println!("Delicious!");
    // Attempting to invoke `func()` again will throw a `Variable was previously moved.`
    // error for `func`.
}

  let x: ByteArray = "x";
  let consume_and_return_x = || x;
  consume_with_relish(consume_and_return_x);
  // `consume_and_return_x` can no longer be invoked at this point

Trait functions

call

Performs the call operation.

Signature

fn call(self: T, args: Args) -> FnOnceOutput

Trait types

Output

The returned type after the call operator is used.

Signature

type Output;