xur_

> built-in type

record

methods of record values

in the browser

Records are untyped values with named fields, written @{ x: 1, name: "text" }. They also come from std::any::record (which turns a struct into a record) and from native functions that return Rust types. These are methods on any record value; there is no module to import.

Records don't change: the set_ methods return a new record and leave the original as it was. Fields keep the order they were written in, and a new field goes at the end. A record's methods are fields that hold a function.

> methods

# record.fields() -> list<str>

The field names, in order.

# record.get_field(name: str) -> Option<any>

The value of field name, or None if the record has no such field.

# record.get_method(name: str) -> Option<fn>

The function stored in field name, or None if there is no such field or its value is not a function.

# record.set_field(name: str, value: any) -> record

A copy of the record with field name set to value. An existing field is replaced in place; otherwise the field is added at the end.

# record.set_method(name: str, func: fn) -> record

Like set_field, but func must be a function, closure or constructor; any other value raises a runtime error.

> examples

use std::io;

fn main() {
    let point = @{ x: 1, y: 2 };
    io::println("fields: {}", point.fields());
    io::println("x = {}", point.get_field("x").unwrap());

    let moved = point.set_field("x", 10);
    io::println("moved = {}, point = {}", moved, point);
}