Call a function field

A struct field whose substituted type is a function can be called through the receiver. This gives callback records the same readable call shape as methods.

An actual method with the same name takes precedence. Function-field calls use exact positional arguments, like every indirect call.

struct Strategy<T> {
  apply: fn(T) -> T,
}

fn main() {
  let strategy: Strategy<int> = Strategy { apply: |value: int| value * 3 }
  println(strategy.apply(4))
}
Output & diagnostics
Expected:
12
Ctrl/⌘+Enter runs the current lesson.