| ... | @@ -53,10 +53,12 @@ pub fn InStream(comptime ReadError: type) type { | ... | @@ -53,10 +53,12 @@ pub fn InStream(comptime ReadError: type) type { |
| 53 | return mem.readInt(bytes, T, endian); | 53 | return mem.readInt(bytes, T, endian); |
| 54 | } | 54 | } |
| 55 | | 55 | |
| 56 | pub async fn readStruct(self: *Self, comptime T: type, ptr: *T) !void { | 56 | pub async fn readStruct(self: *Self, comptime T: type) !T { |
| 57 | // Only extern and packed structs have defined in-memory layout. | 57 | // Only extern and packed structs have defined in-memory layout. |
| 58 | comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); | 58 | comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); |
| 59 | return await (async self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..])) catch unreachable); | 59 | var res: [1]T = undefined; |
| | 60 | try await (async self.readNoEof(@sliceToBytes(res[0..])) catch unreachable); |
| | 61 | return res[0]; |
| 60 | } | 62 | } |
| 61 | }; | 63 | }; |
| 62 | } | 64 | } |