Xen / examples v0.1.0-demo.2
Copies, references, moves
This topic is not available in the selected language or version. Showing the start of this section.
Copies, references, moves
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
xen check examples/ownership.xenxen run examples/ownership.xenExpected output
Section titled “Expected output”[1, 2, 3][1, 2][1, 2, 3]42Complete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0fn 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());}Build an executable
Section titled “Build an executable”xen build examples/ownership.xen -o appRun the generated executable on a compatible Linux machine.