diff options
| author | John Benediktsson <mrjbq7@gmail.com> | 2025-07-17 04:29:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-17 11:29:22 +0000 |
| commit | 6e86910e194ccce076ee877a02b64e0762a270ab (patch) | |
| tree | 9089c8101f165bf7c2ac94f986d5824e4f754424 /lib | |
| parent | c82403020d82718df7d42c9438f3145a9a050640 (diff) | |
| download | zig-6e86910e194ccce076ee877a02b64e0762a270ab.tar.gz zig-6e86910e194ccce076ee877a02b64e0762a270ab.zip | |
std.Io: Fix GenericReader.adaptToNewApi; add DeprecatedReader.adaptToNewApi (#24484)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Io.zig | 2 | ||||
| -rw-r--r-- | lib/std/Io/DeprecatedReader.zig | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/std/Io.zig b/lib/std/Io.zig index d1efb3cbc2..ff6966d7f7 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -320,6 +320,8 @@ pub fn GenericReader( .new_interface = .{ .buffer = &.{}, .vtable = &.{ .stream = Adapter.stream }, + .seek = 0, + .end = 0, }, }; } diff --git a/lib/std/Io/DeprecatedReader.zig b/lib/std/Io/DeprecatedReader.zig index 3f2429c3ae..f6cb9f61d5 100644 --- a/lib/std/Io/DeprecatedReader.zig +++ b/lib/std/Io/DeprecatedReader.zig @@ -372,6 +372,34 @@ pub fn discard(self: Self) anyerror!u64 { } } +/// Helper for bridging to the new `Reader` API while upgrading. +pub fn adaptToNewApi(self: *const Self) Adapter { + return .{ + .derp_reader = self.*, + .new_interface = .{ + .buffer = &.{}, + .vtable = &.{ .stream = Adapter.stream }, + .seek = 0, + .end = 0, + }, + }; +} + +pub const Adapter = struct { + derp_reader: Self, + new_interface: std.io.Reader, + err: ?Error = null, + + fn stream(r: *std.io.Reader, w: *std.io.Writer, limit: std.io.Limit) std.io.Reader.StreamError!usize { + const a: *@This() = @alignCast(@fieldParentPtr("new_interface", r)); + const buf = limit.slice(try w.writableSliceGreedy(1)); + return a.derp_reader.read(buf) catch |err| { + a.err = err; + return error.ReadFailed; + }; + } +}; + const std = @import("../std.zig"); const Self = @This(); const math = std.math; |
