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/ › Io/ › File/ › MultiReader.zig › rebaseGrowing
rebaseGrowing
MultiReader.rebaseGrowing
fn rebaseGrowing (mr : *MultiReader , context : *Context , capacity : usize ) Allocator .Error !void
File
Code
fn rebaseGrowing (mr : *MultiReader , context : *Context , capacity : usize ) Allocator .Error !void {
const gpa = mr .gpa ;
const r = &context .fr .interface ;
if (r .buffer .len >= capacity ) {
const data = r .buffer [r .seek ..r .end ];
@memmove (r .buffer [0 ..data .len ], data );
r .seek = 0 ;
r .end = data .len ;
} else {
const adjusted_capacity = std .ArrayList (u8 ).growCapacity (capacity );
if (r .seek == 0 ) {
if (gpa .remap (r .buffer , adjusted_capacity )) |new_memory | {
r .buffer = new_memory ;
return ;
}
}
const data = r .buffer [r .seek ..r .end ];
const new = try gpa .alloc (u8 , adjusted_capacity );
@memcpy (new [0 ..data .len ], data );
gpa .free (r .buffer );
r .buffer = new ;
r .seek = 0 ;
r .end = data .len ;
}
}