// expect: run // result: 42 // phase: 6 // spec: docs/spec/16-standard-library.md ยง2.15 // grant: heap=mem.alloc:8 module test.hashset import std.hashset; import std.option; fn opened) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(capacity: usize,heap: cap) -> std.hashset.HashSet effects [mem.alloc] { match std.hashset.new::(capacity,heap) { std.hashset.NewResult::::ok(set) => { return move set; }, std.hashset.NewResult::::err(error) => { trap; } } } fn inserted(result: std.hashset.InsertResult) -> void effects [] { match move result { std.hashset.InsertResult::::inserted => {}, std.hashset.InsertResult::::present(key) => { trap; }, std.hashset.InsertResult::::full(key) => { trap; } } } fn extracted(result: std.option.Option) -> K effects [] { match move result { std.option.Option::::some(key) => { return move key; }, std.option.Option::::none => { trap; } } } fn released) -> u64 effects [], E: fn(ref,ref) -> bool effects []>(set: std.hashset.HashSet) -> void effects [] { match std.hashset.free::(move set) { std.hashset.FreeResult::::ok => {}, std.hashset.FreeResult::::not_empty(set) => { trap; } } } struct Key { id: u64, marker: u64 } fn hash(key: ref) -> u64 effects [] { return 3; } fn equal(a: ref,b: ref) -> bool effects [] { return a.id == b.id; } fn main(heap: cap) -> u64 effects [mem.alloc] { match std.hashset.new::((0usize -% 1usize) / 2usize + 1usize,heap) { std.hashset.NewResult::::err(error) => {}, std.hashset.NewResult::::ok(set) => { trap; } } let allocation = own.new(42u64,heap) or trap; return own.take(move allocation); }