Skip to content

References in everyday code

Operators read through references to numbers, bool and Str: v.iter().filter(fn(x) => x > 2) needs no *. Writing still does (*count += 1), so changes through a reference stay visible.

A literal or a temporary can be lent where &T is expected: path.join("src", "main.brass"), shout("a" + "b"). A named variable still needs & (shout(&name)), so borrowing a variable is always written down. Library functions that only read text take &Str.