Working through allocators and trying to figure out an error I'm getting:
const std = @import("std");
const expect = std.testing.expect;
const expectError = std.testing.expectError;
// allocates memory into a fixed buffer and does not make heap allocations
// throws OutOfMemory when runs out of bytes
test "fixed buffer allocator" {
var buffer: [1000]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
var i: usize = 0;
while (i < 11) {
const memory: error{OutOfMemory}![]u8 = allocator.alloc(u8, 100);
if (memory) |m| {
try expect(@TypeOf(m) == []u8);
} else |err| {
expectError(error.OutOfMemory, err);
break;
}
i += 1;
}
}
Getting this error:
error: expected error union type, found 'error{OutOfMemory}'
if (actual_error_union) |actual_payload| {
Must be something trivial, but I'm just so new...