Considerations for future revisions
The items below are not part of the current edition and are not mandatory for implementations; this is material for discussion in the next revisions of the Standard.
- One-shot closures. Currently a closure that moves a captured variable (
let f = () => consume(a)) is the erroruse-after-moveat the place of the move, even if the closure is called exactly once (for example, a combinator function such asor_else); the exception is thespawnclosure, which by definition runs once (implementation decision D-3520). The workaround is to clone the value or create it inside the closure. A possible extension is a separate kind of function type "callable at most once" (an analogue ofFnOnce) checked by the compiler: a call consumes the closure, a repeated call or a copy is an error. The current edition rejected it for the sake of simplicity of the ownership rules and of closure type inference; to be reconsidered if the workaround proves frequent in the standard library and in user code.
Source: docs/spec/oxl-standard.en.md