// A graph charges the authority it was created with; island.alloc fails with alloc_error // when the budget is spent, and destroy returns the bytes. // expect: run // grant: heap=mem.alloc:64 // result: 2 // phase: 6 // spec: docs/spec/03-memory-model.md module demo.islandbudget fn main(heap: cap) -> u64 effects [mem.alloc] { let isl = island.create([0u64; 4], heap) or trap; var outcome: u64 = 0; { mut g = isl; match island.alloc(g, [0u64; 4]) { ok(r) => { outcome = 1; } err(e) => { outcome = match e { alloc_error::budget_exceeded => 2, alloc_error::out_of_memory => 3, }; } } } island.destroy(move isl); let again = island.create([0u64; 4], heap) or trap; island.destroy(move again); outcome }