fixed .fixed flush recursion

This commit is contained in:
Anton Serov 2025-07-10 22:57:09 +03:00 committed by Andrew Kelley
parent f551c7c581
commit d83b95cbf4

View File

@ -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 {