Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.2

Type to search the documentation.

    한국어
    Xen / examples v0.1.0-demo.2

    Structs, enums, tuples

    Structs, enums, tuples

    Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.

    Terminal window
    xen check examples/types.xen
    xen run examples/types.xen
    todo: read the guide
    due in 2
    answer: 42
    types.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    struct Task { title: String, done: Bool }
    enum Priority { Normal, Urgent(Int) }
    impl Task {
    fn label(&self) -> String {
    return if self.done { "done: " + self.title } else { "todo: " + self.title };
    }
    }
    fn main() {
    let task = Task { title: "read the guide", done: false };
    println(task.label());
    let priority = Priority.Urgent(2);
    println(match priority {
    Priority.Normal => "normal",
    Priority.Urgent(days) => "due in " + int_to_str(days),
    });
    let (number, label) = (42, "answer");
    println(label + ": " + int_to_str(number));
    }

    Download file

    Terminal window
    xen build examples/types.xen -o app

    Run the generated executable on a compatible Linux machine.