Skip to content

Commit

Permalink
switched to undefined for initializing array with arbitrary type
Browse files Browse the repository at this point in the history
  • Loading branch information
r4gus committed May 20, 2024
1 parent 29750c9 commit df76bb2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ pub fn ArrayBackedSlice(
const T = [size]U;

return struct {
buffer: T = .{0} ** size,
buffer: T = undefined,
len: usize = 0,

pub fn fromSlice(s: ?[]const U) !?@This() {
if (s == null) return null;
if (s.?.len > size) return error.BufferTooSmall;
var x = @This(){};
@memcpy(x.buffer[0..s.?.len], s.?);
x.len = s.?.len;
return x;
}

pub fn get(self: *const @This()) []const U {
return self.buffer[0..self.len];
}
Expand Down

0 comments on commit df76bb2

Please sign in to comment.