mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
fixed .fixed flush recursion
This commit is contained in:
parent
f551c7c581
commit
d83b95cbf4
1 changed files with 13 additions and 1 deletions
|
|
@ -114,7 +114,10 @@ pub const FileError = error{
|
|||
/// Writes to `buffer` and returns `error.WriteFailed` when it is full.
|
||||
pub fn fixed(buffer: []u8) Writer {
|
||||
return .{
|
||||
.vtable = &.{ .drain = fixedDrain },
|
||||
.vtable = &.{
|
||||
.drain = fixedDrain,
|
||||
.flush = noopFlush,
|
||||
},
|
||||
.buffer = buffer,
|
||||
};
|
||||
}
|
||||
|
|
@ -244,6 +247,15 @@ pub fn noopFlush(w: *Writer) Error!void {
|
|||
_ = w;
|
||||
}
|
||||
|
||||
test "fixed buffer flush" {
|
||||
var buffer: [1]u8 = undefined;
|
||||
var writer: std.io.Writer = .fixed(&buffer);
|
||||
|
||||
try writer.writeByte(10);
|
||||
try writer.flush();
|
||||
try testing.expectEqual(10, buffer[0]);
|
||||
}
|
||||
|
||||
/// Calls `VTable.drain` but hides the last `preserve_length` bytes from the
|
||||
/// implementation, keeping them buffered.
|
||||
pub fn drainPreserve(w: *Writer, preserve_length: usize) Error!void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue