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 › Reader Public Struct Reader Doc Source Public Struct std.testing.Reader
pub const Reader = struct Fields calls : []const Call interface : Io .Reader next_call_index : usize next_offset : usize artificial_limit : Io .Limit = .unlimited Further reduces how many bytes are written in each stream call.
Structs Functions pub fn init (buffer : []u8 , calls : []const Call ) Reader fn stream (io_r : *Io .Reader , w : *Io .Writer , limit : Io .Limit ) Io .Reader .StreamError !usize File testing.zig: 1263
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302 pub const Reader = struct {
calls : []const Call ,
interface : Io .Reader ,
next_call_index : usize ,
next_offset : usize ,
/// Further reduces how many bytes are written in each `stream` call.
artificial_limit : Io .Limit = .unlimited ,
pub const Call = struct {
buffer : []const u8 ,
};
pub fn init (buffer : []u8 , calls : []const Call ) Reader {
return .{
.next_call_index = 0 ,
.next_offset = 0 ,
.interface = .{
.vtable = &.{ .stream = stream },
.buffer = buffer ,
.seek = 0 ,
.end = 0 ,
},
.calls = calls ,
};
}
fn stream (io_r : *Io .Reader , w : *Io .Writer , limit : Io .Limit ) Io .Reader .StreamError !usize {
const r : *Reader = @alignCast (@fieldParentPtr ("interface" , io_r ));
if (r .calls .len - r .next_call_index == 0 ) return error .EndOfStream ;
const call = r .calls [r .next_call_index ];
const buffer = r .artificial_limit .sliceConst (limit .sliceConst (call .buffer [r .next_offset ..]));
const n = try w .write (buffer );
r .next_offset += n ;
if (call .buffer .len - r .next_offset == 0 ) {
r .next_call_index += 1 ;
r .next_offset = 0 ;
}
return n ;
}
}
A
Io.Readerthat writes a predetermined list of buffers duringstream.