From f4606842d26d2de72a1fcfad26a22b32c9cf7a53 Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Thu, 15 Nov 2018 21:03:27 +0100 Subject: [PATCH] Have readStruct in stream return a value instead of taking a pointer --- std/io.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/std/io.zig b/std/io.zig index a59777fd9..7459bbcdf 100644 --- a/std/io.zig +++ b/std/io.zig @@ -188,10 +188,12 @@ pub fn InStream(comptime ReadError: type) type { } } - pub fn readStruct(self: *Self, comptime T: type, ptr: *T) !void { + pub fn readStruct(self: *Self, comptime T: type) !T { // Only extern and packed structs have defined in-memory layout. comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); - return self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..])); + var res: [1]T = undefined; + return self.readNoEof(@sliceToBytes(res[0..])); + return res[0]; } }; }