authorgravatar for codeviolin@gmail.comAnton Serov <codeviolin@gmail.com> 2025-07-10 22:57:09+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-11 05:17:31+02:00
logd83b95cbf4895027b1730ef6025df4fe01beba26
tree971652fc1c51c3447959d51b62de98c3191634ea
parentf551c7c581c7bf1f3324c0611a73c22f2aae82b4

fixed .fixed flush recursion


1 files changed, 13 insertions(+), 1 deletions(-)

lib/std/Io/Writer.zig+13-1
......@@ -114,7 +114,10 @@ pub const FileError = error{
114114/// Writes to `buffer` and returns `error.WriteFailed` when it is full.
115115pub fn fixed(buffer: []u8) Writer {
116116 return .{
117 .vtable = &.{ .drain = fixedDrain },
117 .vtable = &.{
118 .drain = fixedDrain,
119 .flush = noopFlush,
120 },
118121 .buffer = buffer,
119122 };
120123}
......@@ -244,6 +247,15 @@ pub fn noopFlush(w: *Writer) Error!void {
244247 _ = w;
245248}
246249
250test "fixed buffer flush" {
251 var buffer: [1]u8 = undefined;
252 var writer: std.io.Writer = .fixed(&buffer);
253
254 try writer.writeByte(10);
255 try writer.flush();
256 try testing.expectEqual(10, buffer[0]);
257}
258
247259/// Calls `VTable.drain` but hides the last `preserve_length` bytes from the
248260/// implementation, keeping them buffered.
249261pub fn drainPreserve(w: *Writer, preserve_length: usize) Error!void {