Skip to content

Map Operations with ard/map

The ard/map module provides utility functions for working with maps.

The map module provides:

  • Map creation with Map::new() for easily initializing empty maps
use ard/map
fn main() {
let config: [Str:Str] = Map::new()
}

Create a new empty map with string keys. The value type must be explicitly specified.

use ard/map
// Create an empty string-to-string map
let map1: [Str:Str] = Map::new()
// Create an empty string-to-int map
let map2: [Str:Int] = Map::new()
use ard/map
use ard/io
fn main() {
let config: [Str:Str] = Map::new()
config.set("host", "localhost")
config.set("port", "8080")
io::print(config.at("host")) // localhost
}
use ard/map
fn main() {
let settings: [Str:Str] = Map::new()
settings.set("theme", "dark")
settings.set("language", "en")
settings.set("timezone", "UTC")
}
use art/map
fn main() {
let status_codes: [Str:Int] = Map::new()
status_codes.set("ok", 200)
status_codes.set("created", 201)
status_codes.set("bad_request", 400)
status_codes.set("unauthorized", 401)
status_codes.set("not_found", 404)
}