fn canParseTypeInner(
T: type,
/// Visited structs and unions, to avoid infinite recursion.
/// Tracking more types is unnecessary, and a little complex due to optional nesting.
visited: []const type,
parent_is_optional: bool,
) bool T: typevisited: []const typeVisited structs and unions, to avoid infinite recursion. Tracking more types is unnecessary, and a little complex due to optional nesting.
parent_is_optional: bool1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258fn canParseTypeInner(
T: type,
/// Visited structs and unions, to avoid infinite recursion.
/// Tracking more types is unnecessary, and a little complex due to optional nesting.
visited: []const type,
parent_is_optional: bool,
) bool {
return switch (@typeInfo(T)) {
.bool,
.int,
.float,
.null,
.@"enum",
=> true,
.noreturn,
.void,
.type,
.undefined,
.error_union,
.error_set,
.@"fn",
.frame,
.@"anyframe",
.@"opaque",
.spirv,
.comptime_int,
.comptime_float,
.enum_literal,
=> false,
.pointer => |pointer| switch (pointer.size) {
.one => canParseTypeInner(pointer.child, visited, parent_is_optional),
.slice => canParseTypeInner(pointer.child, visited, false),
.many, .c => false,
},
.optional => |optional| if (parent_is_optional)
false
else
canParseTypeInner(optional.child, visited, true),
.array => |array| canParseTypeInner(array.child, visited, false),
.vector => |vector| canParseTypeInner(vector.child, visited, false),
.@"struct" => |@"struct"| {
for (visited) |V| if (T == V) return true;
const new_visited = visited ++ .{T};
for (@"struct".field_types, @"struct".field_attrs) |field_type, field_attrs| {
if (!field_attrs.@"comptime" and !canParseTypeInner(field_type, new_visited, false)) {
return false;
}
}
return true;
},
.@"union" => |@"union"| {
for (visited) |V| if (T == V) return true;
const new_visited = visited ++ .{T};
for (@"union".field_types) |field_type| {
if (field_type != void and !canParseTypeInner(field_type, new_visited, false)) {
return false;
}
}
return true;
},
};
}