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{...@@ -114,7 +114,10 @@ pub const FileError = error{
114/// Writes to `buffer` and returns `error.WriteFailed` when it is full.114/// Writes to `buffer` and returns `error.WriteFailed` when it is full.
115pub fn fixed(buffer: []u8) Writer {115pub fn fixed(buffer: []u8) Writer {
116 return .{116 return .{
117 .vtable = &.{ .drain = fixedDrain },117 .vtable = &.{
118 .drain = fixedDrain,
119 .flush = noopFlush,
120 },
118 .buffer = buffer,121 .buffer = buffer,
119 };122 };
120}123}
...@@ -244,6 +247,15 @@ pub fn noopFlush(w: *Writer) Error!void {...@@ -244,6 +247,15 @@ pub fn noopFlush(w: *Writer) Error!void {
244 _ = w;247 _ = w;
245}248}
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
247/// Calls `VTable.drain` but hides the last `preserve_length` bytes from the259/// Calls `VTable.drain` but hides the last `preserve_length` bytes from the
248/// implementation, keeping them buffered.260/// implementation, keeping them buffered.
249pub fn drainPreserve(w: *Writer, preserve_length: usize) Error!void {261pub fn drainPreserve(w: *Writer, preserve_length: usize) Error!void {