OxL Reference

kw const

Reserved keyword

The list of words: §1.4

Syntax

ebnf
GParam      = Ident [ ":" Bounds ] [ "=" Type ] | "const" Ident ":" Type | "effect" Ident ;
ebnf
Const       = "const" Ident [ ":" Type ] "=" Expr ;

Grammar: App. A

Defined in

Examples

oxl
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" }

— 4.5 impl and methods

oxl
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> { … }

— 4.8 Generics

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

See also