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 library itself.
Zig › std/ › debug.zig › printLineFromFile
printLineFromFile
debug.printLineFromFile
fn printLineFromFile (io : Io , writer : *Writer , source_location : SourceLocation ) !void
File
Code
fn printLineFromFile (io : Io , writer : *Writer , source_location : SourceLocation ) !void {
if (@hasDecl (root , "debug" ) and @hasDecl (root .debug , "printLineFromFile" )) {
return root .debug .printLineFromFile (io , writer , source_location );
}
// be called from e.g. the event loop code crashing.
const cwd : Io .Dir = .cwd ();
var file = try cwd .openFile (io , source_location .file_name , .{});
defer file .close (io );
var buffer : [4096 ]u8 = undefined ;
var file_reader : File .Reader = .init (file , io , &buffer );
var line_index : usize = 0 ;
const r = &file_reader .interface ;
while (true ) {
line_index += 1 ;
if (line_index == source_location .line ) {
_ = try r .streamDelimiterEnding (writer , '\n' );
try writer .writeByte ('\n' );
return ;
}
_ = try r .discardDelimiterInclusive ('\n' );
}
}