Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › testing › SliceDiffer Private Type Function SliceDiffer Doc Source Private Type Function std.testing.SliceDiffer
fn SliceDiffer (comptime T : type ) type Fields start_index : usize expected : []const T actual : []const T terminal_mode : Io .Terminal .Mode Types Functions File testing.zig: 435
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459 fn SliceDiffer (comptime T : type ) type {
return struct {
start_index : usize ,
expected : []const T ,
actual : []const T ,
terminal_mode : Io .Terminal .Mode ,
const Self = @This ();
pub fn write (self : Self , writer : *Io .Writer ) !void {
const t : Io .Terminal = .{ .writer = writer , .mode = self .terminal_mode };
for (self .expected , 0 ..) |value , i | {
const full_index = self .start_index + i ;
const diff = if (i < self .actual .len ) !std .meta .eql (self .actual [i ], value ) else true ;
if (diff ) try t .setColor (.red );
if (@typeInfo (T ) == .pointer ) {
try writer .print ("[{}]{*}: {any}\n" , .{ full_index , value , value });
} else {
try writer .print ("[{}]: {any}\n" , .{ full_index , value });
}
if (diff ) try t .setColor (.reset );
}
}
};
}