authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-11-15 21:03:27+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-11-15 21:03:27+01:00
logf4606842d26d2de72a1fcfad26a22b32c9cf7a53
treed536b172d598df3d4974d18a44c5c533c50eabbb
parent2a9843de953a345cdf74a85a0ce54d97fd7a8a7b

Have readStruct in stream return a value instead of taking a pointer


1 files changed, 4 insertions(+), 2 deletions(-)

std/io.zig+4-2
...@@ -188,10 +188,12 @@ pub fn InStream(comptime ReadError: type) type {...@@ -188,10 +188,12 @@ pub fn InStream(comptime ReadError: type) type {
188 }188 }
189 }189 }
190190
191 pub fn readStruct(self: *Self, comptime T: type, ptr: *T) !void {191 pub fn readStruct(self: *Self, comptime T: type) !T {
192 // Only extern and packed structs have defined in-memory layout.192 // Only extern and packed structs have defined in-memory layout.
193 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);193 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
194 return self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..]));194 var res: [1]T = undefined;
195 return self.readNoEof(@sliceToBytes(res[0..]));
196 return res[0];
195 }197 }
196 };198 };
197}199}