I’m new to Zig and I’m trying to make a test project to learn it. Is there a way to cast a *[ ]const u8 to *anyopaque? Because when I try to build and run this code:
var x: []const u8 = "hello world!";
const ptr_x: *[]const u8 = &x;
const any: Any = Any.init(ptr_x);
In Any.init():
pub fn init(p_val: anytype) @This() {
return @This(){
.val: *anyopaque = p_val,
.type_info = //...
};
}
It gives me a compile error:
src\any\any.zig:10:10: error: expected type '*anyopaque', found '*[]const u8'
.val = p_val,
~^~~~~~~~~~~
src\any\any.zig:10:10: note: cannot implicitly cast double pointer '*[]const u8' to anyopaque pointer '*anyopaque'