nativity/lib/std/data_structures/pinned_array.nat
2024-04-08 19:45:13 -06:00

16 lines
431 B
Plaintext

const std = #import("std");
const assert = std.assert;
const PinnedArray = struct(.{ .sliceable = true }, $T) {
pointer: [&]T = #cast(0),
length: u32 = 0,
capacity: u32 = 0,
const append_with_capacity = fn (pinned_array: &Self, item: T) void {
const index = pinned_array.length;
assert(index < pinned_array.capacity);
pinned_array.length += 1;
pinned_array[index] = item;
}
};