kw const
Reserved keyword
The list of words: §1.4
Syntax
GParam = Ident [ ":" Bounds ] [ "=" Type ] | "const" Ident ":" Type | "effect" Ident ;Const = "const" Ident [ ":" Type ] "=" Expr ;Grammar: App. A
Defined in
- 4.5 impl and methods — Inside a method self and Self are available.
- 4.8 Generics — Parameters: type parameters T, constant parameters const N
- 2.4 Entry points and start-up order — A program is a package that contains at least one of
- 4.1 Variables and constants — There are no mutable globals without sync.
- 4.9 Attributes — Syntax: @name or @name(arguments) before a declaration, field, parameter or rpc.
- 14.1 Static configuration — config Name { … } declares a typed config.
- 15.1 comptime — A comptime fn is executed only at compile time; comptime { …
- 1.4 Keywords — Reserved (cannot be used as names)
Examples
impl Money {
pub const ZERO: Money = Money{ minor: 0 }
pub const MAX_TRANSFER: Money = Money.rub(1_000_000)
}
interface Codec<T> { const NAME: str } // the implementation must supply a value
impl Codec<Point> for GeoHashCodec { const NAME: str = "geohash" }fn max<T>(a: T, b: T) -> T where T: Ord => if a > b { a } else { b }
data Page<T> where T: Serializable { items: List<T>; next: Cursor? }
data Matrix<const R: usize, const C: usize> { cells: [f64; R * C] }
fn pack<T>(x: T) -> bytes where T: Serializable, size_of(T) <= 4KiB
data Cache<K: Hash + Eq, V = bytes> { … }Related diagnostics
impl-foreign-type, unknown-method, bound-not-satisfied, generic-args, no-entry-point, global-mutable, mutate-immutable, deprecated, config-type, comptime-error, not-comptime