Closures

Closures

Closures implement three types of traits from standard library

  1. Fn -> Immutable borrowing of values from outer scope

  2. FnMut -> Mutable borrow of values from outer scope

  3. FnOnce -> Takes the ownership from the outer scope

move keyword is used to move the ownership of outer scope variables to inside of closure

//example
let closure = |var| {
.....
...// write logic
}

Last updated

Was this helpful?