A compile time trick.
As you probably already realized, the type of a string is not []const u8
but a 0 sentinel const array of u8 with the length of the string as size. This is impossible to match as type
.
But I devised a trick to detect if a anytype value is an actual string.
@TypeOf
can have multiple arguments and returns the type that all the arguments can coerce to.
fn isString(comptime v: anytype) bool {
const str: []const u8 = "";
return @TypeOf(str, v) == []const u8;
}