Hello everyone,
Recently I have run into a problem and I think that I have figured out the reason – I have a structure that holds data, some of which is dynamic.
I have decided to make it the most zig-like and in it’s init
allow for setting the allocator.
Allocating works fine but now I cannot stringify my structure
+- zig build-exe zig Debug native 5 errors
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: error: cannot load opaque type 'anyopaque'
return self.write(value.*);
~~~~~^~
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: error: values of type 'fn (*anyopaque, usize, mem.Alignment, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
return self.write(value.*);
~~~~~^~
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: note: use '*const fn (*anyopaque, usize, mem.Alignment, usize) ?[*]u8' for a function pointer type
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: error: values of type 'fn (*anyopaque, []u8, mem.Alignment, usize, usize) bool' must be comptime-known, but operand value is runtime-known
return self.write(value.*);
~~~~~^~
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: note: use '*const fn (*anyopaque, []u8, mem.Alignment, usize, usize) bool' for a function pointer type
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: error: values of type 'fn (*anyopaque, []u8, mem.Alignment, usize, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
return self.write(value.*);
~~~~~^~
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: note: use '*const fn (*anyopaque, []u8, mem.Alignment, usize, usize) ?[*]u8' for a function pointer type
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: error: values of type 'fn (*anyopaque, []u8, mem.Alignment, usize) void' must be comptime-known, but operand value is runtime-known
return self.write(value.*);
~~~~~^~
/opt/zig-bin-0.14.0/lib/std/json/stringify.zig:641:52: note: use '*const fn (*anyopaque, []u8, mem.Alignment, usize) void' for a function pointer type
I do not need the allocator JSONed, I just need the data.
The only solution I can think of is to not include it a structure by hardcoding it
Do you have any better ideas?