authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-01 20:34:55-08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-01 20:34:55-08:00
log53ebfde6b433ebdb28d4989a345e8d34abf049b7
tree80d82c15ad88ad112a6c6d416f231a2a275ceb3a
parent0c5f879b981352a84edb6daa09a1d6cdb53378d7

std: use decl literals to improve endian ergonomics


2 files changed, 7 insertions(+), 0 deletions(-)

lib/std/builtin.zig+3
......@@ -841,6 +841,9 @@ pub const FloatMode = enum {
841841pub const Endian = enum {
842842 big,
843843 little,
844
845 pub const native = builtin.target.cpu.arch.endian();
846 pub const foreign: Endian = @enumFromInt(1 - @intFromEnum(native));
844847};
845848
846849/// This data structure is used by the Zig language code generation and
lib/std/mem.zig+4
......@@ -2006,11 +2006,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
20062006 } else return @as(T, @bitCast(val));
20072007}
20082008
2009/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .native)
20092010pub const readPackedIntNative = switch (native_endian) {
20102011 .little => readPackedIntLittle,
20112012 .big => readPackedIntBig,
20122013};
20132014
2015/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .foreign)
20142016pub const readPackedIntForeign = switch (native_endian) {
20152017 .little => readPackedIntBig,
20162018 .big => readPackedIntLittle,
......@@ -2159,11 +2161,13 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
21592161 writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big);
21602162}
21612163
2164/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .native)
21622165pub const writePackedIntNative = switch (native_endian) {
21632166 .little => writePackedIntLittle,
21642167 .big => writePackedIntBig,
21652168};
21662169
2170/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .foreign)
21672171pub const writePackedIntForeign = switch (native_endian) {
21682172 .little => writePackedIntBig,
21692173 .big => writePackedIntLittle,