capture mode
How a closure holds a variable it uses: by borrowing it, borrowing it mutably, or taking it.
Each variable a closure uses is captured by shared reference, mutable reference, or by value, whichever is the least the body needs (unless move forces by value).
Loading interactive…
Examples
|| println!("welcome to {shop}")borrowsshop,|| stamps += 1borrowsstampsmutably, and a body withlet archived = receipt;takesreceiptby value.
See also