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

    Copies, references, moves

    Copies, references, moves

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

    Terminal window
    xen check examples/ownership.xen
    xen run examples/ownership.xen
    [1, 2, 3]
    [1, 2]
    [1, 2, 3]
    42
    ownership.xen
    // SPDX-License-Identifier: MIT OR Apache-2.0
    fn append_copy(values: Vec<Int>) {
    let mut copy = values;
    copy.push(3);
    println(copy);
    }
    #![explc]
    fn append_shared(values: &mut Vec<Int>) {
    values.push(3);
    }
    #![explc]
    fn main() {
    let mut values = [1, 2];
    append_copy(values);
    println(values);
    append_shared(&mut values);
    println(values);
    let original = box(42);
    let transferred = original;
    println(transferred.into_inner());
    }

    Download file

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

    Run the generated executable on a compatible Linux machine.