authorgravatar for mrjbq7@gmail.comJohn Benediktsson <mrjbq7@gmail.com> 2025-07-17 04:29:22-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-17 11:29:22+00:00
log6e86910e194ccce076ee877a02b64e0762a270ab
tree9089c8101f165bf7c2ac94f986d5824e4f754424
parentc82403020d82718df7d42c9438f3145a9a050640
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.Io: Fix GenericReader.adaptToNewApi; add DeprecatedReader.adaptToNewApi (#24484)


2 files changed, 30 insertions(+), 0 deletions(-)

lib/std/Io.zig+2
......@@ -320,6 +320,8 @@ pub fn GenericReader(
320320 .new_interface = .{
321321 .buffer = &.{},
322322 .vtable = &.{ .stream = Adapter.stream },
323 .seek = 0,
324 .end = 0,
323325 },
324326 };
325327 }
lib/std/Io/DeprecatedReader.zig+28
......@@ -372,6 +372,34 @@ pub fn discard(self: Self) anyerror!u64 {
372372 }
373373}
374374
375/// Helper for bridging to the new `Reader` API while upgrading.
376pub fn adaptToNewApi(self: *const Self) Adapter {
377 return .{
378 .derp_reader = self.*,
379 .new_interface = .{
380 .buffer = &.{},
381 .vtable = &.{ .stream = Adapter.stream },
382 .seek = 0,
383 .end = 0,
384 },
385 };
386}
387
388pub const Adapter = struct {
389 derp_reader: Self,
390 new_interface: std.io.Reader,
391 err: ?Error = null,
392
393 fn stream(r: *std.io.Reader, w: *std.io.Writer, limit: std.io.Limit) std.io.Reader.StreamError!usize {
394 const a: *@This() = @alignCast(@fieldParentPtr("new_interface", r));
395 const buf = limit.slice(try w.writableSliceGreedy(1));
396 return a.derp_reader.read(buf) catch |err| {
397 a.err = err;
398 return error.ReadFailed;
399 };
400 }
401};
402
375403const std = @import("../std.zig");
376404const Self = @This();
377405const math = std.math;