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 › Io › Writer › Discarding Public Struct Discarding Doc Source Public Struct std.Io.Writer.Discarding
pub const Discarding = struct Fields Functions File Io/Writer.zig: 2345
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397 pub const Discarding = struct {
count : u64 ,
writer : Writer ,
pub fn init (buffer : []u8 ) Discarding {
return .{
.count = 0 ,
.writer = .{
.vtable = &.{
.drain = Discarding .drain ,
.sendFile = Discarding .sendFile ,
},
.buffer = buffer ,
},
};
}
/// Includes buffered data (no need to flush).
pub fn fullCount (d : *const Discarding ) u64 {
return d .count + d .writer .end ;
}
pub fn drain (w : *Writer , data : []const []const u8 , splat : usize ) Error !usize {
const d : *Discarding = @alignCast (@fieldParentPtr ("writer" , w ));
const slice = data [0 .. data .len - 1 ];
const pattern = data [slice .len ];
var written : usize = pattern .len * splat ;
for (slice ) |bytes | written += bytes .len ;
d .count += w .end + written ;
w .end = 0 ;
return written ;
}
pub fn sendFile (w : *Writer , file_reader : *File .Reader , limit : Limit ) FileError !usize {
if (File .Handle == void ) return error .Unimplemented ;
const d : *Discarding = @alignCast (@fieldParentPtr ("writer" , w ));
d .count += w .end ;
w .end = 0 ;
if (limit == .nothing ) return 0 ;
if (file_reader .getSize ()) |size | {
const n = limit .minInt64 (size - file_reader .pos );
if (n == 0 ) return error .EndOfStream ;
file_reader .seekBy (@intCast (n )) catch return error .Unimplemented ;
w .end = 0 ;
d .count += n ;
return n ;
} else |_ | {
// Error is observable on `file_reader` instance, and it is better to
// treat the file as a pipe.
return error .Unimplemented ;
}
}
}