Struct std::ops::Function

Overview

The type of a function in Rune.

Functions can be called using call expression syntax, such as <expr>().

There are multiple different kind of things which can be coerced into a function in Rune:

  • Regular functions.
  • Closures (which might or might not capture their environment).
  • Built-in constructors for tuple types (tuple structs, tuple variants).

Examples

// Captures the constructor for the `Some(<value>)` tuple variant.
let build_some = Some;
assert_eq!(build_some(42), Some(42));

fn build(value) {
   Some(value)
}

// Captures the function previously defined.
let build_some = build;
assert_eq!(build_some(42), Some(42));

Trait Implementations

impl Clone for Function
fn clone(value: any) -> any

Clone the specified value.

Examples

let a = 42;
let b = a;
let c = a.clone();

a += 1;

assert_eq!(a, 43);
assert_eq!(b, 42);
assert_eq!(c, 42);

Protocols

protocol CLONE
let $out = clone(value)

Clone a function.

Examples

fn function() {
   42
}

let a = function;
let b = a.clone();
assert_eq!(a(), b());
protocol DEBUG_FMT
format!("{:?}", value)

Debug format a function.

Examples

fn function() {
   42
}

println!("{function:?}");
``