-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_string_string.ko
More file actions
54 lines (44 loc) · 1.44 KB
/
map_string_string.ko
File metadata and controls
54 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module map_string_string {
meta {
description: "Demonstrates Map<String, String> operations"
purpose: "Example of generic Map with String keys and values"
version: "1.0.0"
}
fn main() {
let m: Map<String, String> = map_new()
// Insert key-value pairs
map_insert(m, "name", "Kodo")
map_insert(m, "lang", "Rust")
map_insert(m, "type", "compiler")
// Length
let len: Int = map_length(m)
println(f"Map has {len} entries")
// Get values
let name: String = map_get(m, "name")
println(f"name = {name}")
let lang: String = map_get(m, "lang")
println(f"lang = {lang}")
// Contains key
let has_name: Bool = map_contains_key(m, "name")
if has_name {
println("Has key 'name': true")
}
let has_missing: Bool = map_contains_key(m, "missing")
if has_missing {
println("ERROR: should not have 'missing'")
} else {
println("Has key 'missing': false")
}
// Overwrite
map_insert(m, "lang", "Kodo")
let updated: String = map_get(m, "lang")
println(f"updated lang = {updated}")
// Remove
let removed: Bool = m.remove("type")
if removed {
println("Removed 'type': true")
}
let final_len: Int = map_length(m)
println(f"Final length: {final_len}")
}
}