Payload captures use the syntax |value| and appear in many places, some of
which we’ve seen already. Wherever they appear, they are used to “capture” the
value from something.
With if statements and optionals.
With if statements and error unions. The else with the error capture is required
here.
With while loops and optionals. This may have an else block.
With while loops and error unions. The else with the error capture is required
here.
For loops.
Switch cases on tagged unions.
As we saw in the Union and Optional sections above, values captured with the
|val| syntax are immutable (similar to function arguments), but we can use
pointer capture to modify the original values. This captures the values as
pointers that are themselves still immutable, but because the value is now a
pointer, we can modify the original value by dereferencing it: