Initial commit
This commit is contained in:
commit
5f2e19904d
9 changed files with 503 additions and 0 deletions
20
src/utils/Lazy.zig
Normal file
20
src/utils/Lazy.zig
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn Lazy(comptime T: type, comptime init_fn: std.meta.DeclEnum(T)) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
|
||||
value: ?T = null,
|
||||
|
||||
pub fn get(self: *Self) *T {
|
||||
return if (self.value) |*v| v else blk: {
|
||||
self.value = @field(T, @tagName(init_fn))();
|
||||
break :blk &self.value.?;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn lazy(comptime T: type, comptime init_fn: std.meta.DeclEnum(T)) Lazy(T, init_fn) {
|
||||
return .{};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue