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

    Reuse with different types

    Reuse with different types

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

    Terminal window
    xen check examples/generics.xen
    xen run examples/generics.xen
    7
    hello
    generics.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    struct Pair<T> { first: T, second: T }
    fn identity<T>(value: T) -> T {
    return value;
    }
    fn main() {
    let pair = Pair<Int> { first: identity(7), second: 9 };
    println(pair.first);
    println(identity<String>("hello"));
    }

    Download file

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

    Run the generated executable on a compatible Linux machine.