mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
fixed .fixed flush recursion
This commit is contained in:
parent
f551c7c581
commit
d83b95cbf4
@ -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…
x
Reference in New Issue
Block a user