I want to create a generic structure with functions that can modify the value of fields in the comptime type. This works fine in my testing, but I want to make sure that types missing the proper fields cannot be passed into the generic. In the code below is there a way to check the type of .pointer in T?
fn getMyGeneric(comptime T: type) type {
comptime {
if (!@hasField(T, "pointer")) @compileError("No pointer");
if (@TypeOf( ??? ) != *T) @compileError("pointer is not type *T"); //How to check that pointer is of type *T
}
return struct {
pointer: *T,
const Self = @This();
pub fn set(self: *Self, obj: *T) void {
obj.pointer = self.pointer;
}
};
}