January 2019
Beginner to intermediate
554 pages
13h 31m
English
Closures that take ownership of the data they read from their environment get implemented with FnOnce. The name signifies that this closure can only be called once and, because of that, the variables are available only once. This is the least recommended way to construct and use closures, because you cannot use the referenced variables later:
// fn_once.rsfn main() { let mut a = Box::new(23); let call_me = || { let c = a; }; call_me(); call_me();}
This fails with the following error:

But there are use cases where FnOnce closures are the only applicable closures. One such example is the thread::spawn method in the standard ...
Read now
Unlock full access