Xen / examples v0.1.0-demo.2
Lookup by key
This topic is not available in the selected language or version. Showing the start of this section.
Lookup by key
Run from the repository or distribution root. Put xen on PATH, or substitute ./bin/xen.
xen check examples/hashmap.xenxen run examples/hashmap.xenExpected output
Section titled “Expected output”32Complete source
Section titled “Complete source”// SPDX-License-Identifier: MIT OR Apache-2.0use std.hashmap as hashmap;
#![explc]fn main() { let mut prices = hashmap.new<Int>(); prices.insert("tea", 3); prices.insert("coffee", 4); let key = "tea"; println(match prices.get_cloned(&key) { Option.Some(price) => price, Option.None => 0, }); println(prices.len());}Build an executable
Section titled “Build an executable”xen build examples/hashmap.xen -o appRun the generated executable on a compatible Linux machine.