OxL Reference

4.5 impl and methods

Declaration in implReceiver
fn m()&self
var fn m()&var self
move fn m()self by value (move)
static fn m()none, called as T.m()
init m()constructor (§4.3)
op +(…)operator (§5.3)
  • Inside a method self and Self are available. Fields and methods are available without self. unless the name is shadowed by a local variable.
  • impl T { … } MUST be located in the package that declared T.
  • impl I for T { … } is an explicit implementation of an interface. Allowed if I or T is declared in the current package.

Associated constants. const NAME: T = e inside impl T or interface declares a constant of the type, available as T.NAME:

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" }
  • e MUST be a comptime expression; calls are allowed only to comptime functions and to constructors without effects.
  • An interface constant without a value is mandatory for an implementation; with a value — it is the default.
  • Associated constants are allowed in attribute arguments (@timeout(Limits.CHECKOUT)).

impl-foreign-type, unknown-method

See also

Source: docs/spec/oxl-standard.en.md