DVUI

validateFieldPtrTypeString

Validate is a pointer to a u8 slice.

Parameters

#
field_name:?[]const u8
?[]const u8
caller:[]const u8
[]const u8
ptr_type:type
type

Source

Implementation

#
pub fn validateFieldPtrTypeString(field_name: ?[]const u8, comptime caller: []const u8, comptime ptr_type: type) void {
    switch (@typeInfo(ptr_type)) {
        .pointer => |p| {
            switch (@typeInfo(p.child)) {
                .pointer => |ptr| {
                    if (ptr.size == .slice and ptr.child == u8)
                        return;
                },
                else => {},
            }
        },
        else => {},
    }
    @compileError(std.fmt.comptimePrint(
        "Field {s} cannot be displayed. {s} requires a pointer to a []u8 or []const u8, but received a {s}.",
        .{ field_name orelse "", caller, @typeName(ptr_type) },
    ));
}