Constants
A constant is a named, compile-time value.
NAME— a plain identifier (not scoped).Type— any type; in practice a primitive.value— one of:- a literal: an integer or a
"quoted string"(plain, no interpolation) - an identifier — another constant, by name
- a
::-path —u32::MIN,pkg::mod::DEFAULT - an f-string —
f"page {N} of {total}", with{path}placeholders and{{/}}escapes (same interpolation as anerror'smessage)
- a literal: an integer or a
Everything except a plain literal is recorded as text and not resolved to a
value yet — including the {N} in an f-string.
A constant can carry a docstring:
Using one
A constant is referenced by name as a struct field default:
Array sizes currently take an integer literal only (Article[10]), not a
constant name.