| ... | @@ -698,17 +698,36 @@ pub const AnyReader = struct { | ... | @@ -698,17 +698,36 @@ pub const AnyReader = struct { |
| 698 | const R = @TypeOf(reader); | 698 | const R = @TypeOf(reader); |
| 699 | const ctx = reader.context; | 699 | const ctx = reader.context; |
| 700 | const Ctx = @TypeOf(ctx); | 700 | const Ctx = @TypeOf(ctx); |
| 701 | comptime std.debug.assert(std.meta.trait.is(.Pointer)(Ctx)); | 701 | switch (@typeInfo(Ctx)) { |
| 702 | const S = struct { | 702 | .Pointer => { |
| 703 | fn foo(s: *anyopaque, buffer: []u8) anyerror!usize { | 703 | const S = struct { |
| 704 | const r = R{ .context = @ptrCast(@alignCast(s)) }; | 704 | fn foo(s: *anyopaque, buffer: []u8) anyerror!usize { |
| 705 | return r.read(buffer); | 705 | const r = R{ .context = @ptrCast(@alignCast(s)) }; |
| 706 | } | 706 | return r.read(buffer); |
| 707 | }; | 707 | } |
| 708 | return .{ | 708 | }; |
| 709 | .readFn = S.foo, | 709 | return .{ |
| 710 | .state = ctx, | 710 | .readFn = S.foo, |
| 711 | }; | 711 | .state = ctx, |
| | 712 | }; |
| | 713 | }, |
| | 714 | .Struct => switch (R) { |
| | 715 | std.fs.File.Reader => { |
| | 716 | const S = struct { |
| | 717 | fn foo(s: *anyopaque, buffer: []u8) anyerror!usize { |
| | 718 | const r = R{ .context = .{ .handle = @intCast(@intFromPtr(s)) } }; |
| | 719 | return r.read(buffer); |
| | 720 | } |
| | 721 | }; |
| | 722 | return .{ |
| | 723 | .readFn = S.foo, |
| | 724 | .state = @ptrFromInt(@as(usize, @intCast(ctx.handle))), |
| | 725 | }; |
| | 726 | }, |
| | 727 | else => @compileError(@typeName(R)), |
| | 728 | }, |
| | 729 | else => |v| @compileError(@typeName(R) ++ " , " ++ @tagName(v)), |
| | 730 | } |
| 712 | } | 731 | } |
| 713 | | 732 | |
| 714 | pub fn read(r: AnyReader, buffer: []u8) anyerror!usize { | 733 | pub fn read(r: AnyReader, buffer: []u8) anyerror!usize { |