Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Collections and Handles

Placeholder: Brief overview. For detailed specifications, see the collections and pools specs.

Three Collection Types

Vec - Ordered, indexed access:

const v = Vec.new()
try v.push(1)
try v.push(2)
const first = v[0]         // Copy out (if T: Copy)

Map<K,V> - Key-value lookup:

const m = Map.new()
try m.insert("key", "value")
const val = m.get("key")   // Returns Option<V>

Pool<T> - Handle-based storage for graphs:

const pool = Pool.new()
const h1 = try pool.insert(Node.new())
const h2 = try pool.insert(Node.new())
h1.next = h2               // Store handle, not reference

Why Handles?

References can’t be stored in Rask (no lifetime annotations). For graphs, cycles, and entity systems, use Pool\<T\> with handles:

struct Node {
    value: i32,
    next: Option<Handle<Node>>,
}

const pool = Pool.new()
const h1 = try pool.insert(Node { value: 1, next: None })
const h2 = try pool.insert(Node { value: 2, next: Some(h1) })

Handles are validated at runtime:

  • Pool ID check (right pool?)
  • Generation check (still valid?)
  • Index bounds check

Iteration

for i in vec {
    println(vec[i])        // Index iteration
}

for h in pool {
    println(pool[h].value) // Handle iteration
}

for i in 0..10 {
    println(i)             // Range iteration
}

Next Steps