I have this function:
fn diffAny(comptime T: type, comptime Path: []const u8, pathArgs: anytype, a: T, b: T, depth: u8, differences:*Diffs, gpa: std.mem.Allocator) void {
switch (@typeInfo(T)) {
// other cases deleted, to have a short message
.array => |ar| {
if (a.len != b.len) {
var newD = differences.differences.addOne(gpa) catch unreachable;
newD.path = std.fmt.allocPrint(gpa, Path ++ ".len", pathArgs) catch unreachable;
newD.depth = depth;
newD.diff = std.fmt.allocPrint(gpa, "{} != {}", .{ a.len, b.len }) catch unreachable;
}
// TODO update pathArgs with index
for (a, b) |aI, bI|diffAny(ar.child, Path ++ "[]", pathArgs, aI, bI, depth + 1, differences, gpa);
},
else => @compileError("Unreachable. " ++ @typeName(T) ++ " is unexpected"),
}
}
And I would like for Path ++ "[]" to be Path ++ "[{}]", and somehow add index to the pathArgs.
I believe such thing is possible, because I can generate types at compile time, but the index will be a runtime value, but that is only assignment, but I can not even figure out the correct question, for search engines to understand.