aboutsummaryrefslogtreecommitdiff
path: root/std/io.zig
diff options
context:
space:
mode:
Diffstat (limited to 'std/io.zig')
-rw-r--r--std/io.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/std/io.zig b/std/io.zig
index c7154065cb..369f6eede3 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -207,6 +207,12 @@ pub fn InStream(comptime ReadError: type) type {
_ = try self.readByte();
}
}
+
+ pub fn readStruct(self: *Self, comptime T: type, ptr: *T) !void {
+ // Only extern and packed structs have defined in-memory layout.
+ assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
+ return self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..]));
+ }
};
}