From 1e1f026c8355c8cd4c6efb5b7fc42e5b2091e1f2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 30 Jun 2025 15:36:12 -0700 Subject: [PATCH] std.mem.byteSwapAllFields: support slices --- lib/std/mem.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 59c26cc8879f534a5f7560e979cd5663fced485d..a5613536c6a417f26ef1d782e3f18d6eb71f688a 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1714,7 +1714,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) } }, } - return @as(ReturnType, @truncate(result)); + return @truncate(result); } test readVarInt { @@ -2196,7 +2196,9 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { } } }, - else => @compileError("byteSwapAllFields expects a struct or array as the first argument"), + else => { + ptr.* = @byteSwap(ptr.*); + }, } } -- 2.54.0