commit d83b95cbf4895027b1730ef6025df4fe01beba26 (tree)
parent f551c7c581c7bf1f3324c0611a73c22f2aae82b4
Author: Anton Serov <codeviolin@gmail.com>
Date: Thu, 10 Jul 2025 22:57:09 +0300
fixed .fixed flush recursion
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig
@@ -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 {