OxL Reference

op (

(

Defined in

Examples

oxl
impl Vec3 {
  static op +(a: Vec3, b: Vec3) -> Vec3 => Vec3(a.x + b.x, a.y + b.y, a.z + b.z)
  static op *(v: Vec3, k: f32) -> Vec3 => Vec3(v.x * k, v.y * k, v.z * k)
  static op -(v: Vec3) -> Vec3 => v * -1.0
  op [](i: usize) -> f32 { … }            // read by index
  var op [](i: usize) -> &var f32 { … }   // write by index
  op ()(t: f32) -> Vec3 { … }             // call as a function
  static op <=>(a: Vec3, b: Vec3) -> Ordering { … }
  op as Vec4 => Vec4(x, y, z, 1.0)
}

— 5.3 Overloading and user-defined operators

oxl
@explicit interface Codec<T> {
  static fn encode(x: &T, w: &var Encoder) -> () | EncodeError
  static fn decode(r: &var Decoder) -> T | DecodeError
  static fn schema() -> Schema               // for oxl export
}

data Event {
  @codec(json: Iso8601) at: Time            // in JSON an ISO 8601 string, in binary the default
  @codec(Base64Url) token: bytes             // in all formats
}

@codec(GeoHashCodec) data Point { lat: f64; lon: f64 }

— 9.5 User-defined serialisers

Related diagnostics

chained-comparison, not-callable, not-overloadable, operator-decl, range-not-iterable, invalid-char, bad-init, missing-field, must-close, positional-literal, sealed-literal, schema-attr, cluster-auth

See also