diff --git a/build.zig b/build.zig index 15ff56b7c7a101fcd18d69cdbcb3a04a31555733..7b40c63125dadc6277995db39df1fa6718c94ba7 100644 --- a/build.zig +++ b/build.zig @@ -1,12 +1,12 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; _ = b.addModule( "extras", - .{ .source_file = .{ .path = "src/lib.zig" } }, + .{ .root_source_file = .{ .path = "src/lib.zig" } }, ); const exe_unit_tests = b.addTest(.{ diff --git a/src/BufIndexer.zig b/src/BufIndexer.zig index 7a14cd1e1410c34f1523452e78d782de968c248b..f3f3a26840d0fcdc1958dbf0128ab3bde419fa46 100644 --- a/src/BufIndexer.zig +++ b/src/BufIndexer.zig @@ -27,20 +27,20 @@ pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type { test { const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); - const bindex = BufIndexer(u64, .Big).init(&bytes, 1); + const bindex = BufIndexer(u64, .big).init(&bytes, 1); try std.testing.expect(bindex.at(0) == 0x4e5a7da9f3f1d132); } test { const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); - const bindex = BufIndexer(u32, .Big).init(&bytes, 2); + const bindex = BufIndexer(u32, .big).init(&bytes, 2); try std.testing.expect(bindex.at(0) == 0x4e5a7da9); try std.testing.expect(bindex.at(1) == 0xf3f1d132); } test { const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); - const bindex = BufIndexer(u16, .Big).init(&bytes, 4); + const bindex = BufIndexer(u16, .big).init(&bytes, 4); try std.testing.expect(bindex.at(0) == 0x4e5a); try std.testing.expect(bindex.at(1) == 0x7da9); try std.testing.expect(bindex.at(2) == 0xf3f1); @@ -49,7 +49,7 @@ test { test { const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); - const bindex = BufIndexer(u8, .Big).init(&bytes, 8); + const bindex = BufIndexer(u8, .big).init(&bytes, 8); try std.testing.expect(bindex.at(0) == 0x4e); try std.testing.expect(bindex.at(1) == 0x5a); try std.testing.expect(bindex.at(2) == 0x7d); diff --git a/src/FieldUnion.zig b/src/FieldUnion.zig index 79312957937381f30483c961bfbc47fd9a292d80..9ccc6d18851bdc8128126c1f121fe079620921c7 100644 --- a/src/FieldUnion.zig +++ b/src/FieldUnion.zig @@ -15,7 +15,7 @@ pub fn FieldUnion(comptime T: type) type { }; } return @Type(std.builtin.Type{ .Union = .{ - .layout = .Auto, + .layout = .auto, .tag_type = std.meta.FieldEnum(T), .fields = &fields, .decls = &.{}, diff --git a/src/Partial.zig b/src/Partial.zig index 147636e38a3e9b621c7ca12f7fa2d1508773ece9..c702a7ba89bec32ad1662c6b0d6dc20223c48e30 100644 --- a/src/Partial.zig +++ b/src/Partial.zig @@ -18,7 +18,7 @@ pub fn Partial(comptime T: type) type { }; } return @Type(@unionInit(std.builtin.Type, "Struct", .{ - .layout = .Auto, + .layout = .auto, .backing_integer = null, .fields = &fields_after, .decls = &.{}, diff --git a/src/base64DecodeAlloc.zig b/src/base64DecodeAlloc.zig index 2e297e82b0751064f2ff19d823fe814c8c647c18..866dd9b46b8e89fadf3f895921bc42df88144b0f 100644 --- a/src/base64DecodeAlloc.zig +++ b/src/base64DecodeAlloc.zig @@ -4,7 +4,7 @@ const extras = @import("./lib.zig"); pub fn base64DecodeAlloc(alloc: std.mem.Allocator, input: string) !string { const base64 = std.base64.standard.Decoder; - var buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input)); + const buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input)); try base64.decode(buf, input); return buf; } diff --git a/src/base64EncodeAlloc.zig b/src/base64EncodeAlloc.zig index 39bba1ca5c493d1ac7f0a2f14243eabdff19181b..7db2b217c08178f1b9f124e49976cfe8ff45cb89 100644 --- a/src/base64EncodeAlloc.zig +++ b/src/base64EncodeAlloc.zig @@ -4,7 +4,7 @@ const extras = @import("./lib.zig"); pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string { const base64 = std.base64.standard.Encoder; - var buf = try alloc.alloc(u8, base64.calcSize(input.len)); + const buf = try alloc.alloc(u8, base64.calcSize(input.len)); return base64.encode(buf, input); } diff --git a/src/dirSize.zig b/src/dirSize.zig index ebd1cf62c72597d1e38ee42b737c6ba57c108efb..7dcdffe2fc881c4c83cb85786cb29f80b8771577 100644 --- a/src/dirSize.zig +++ b/src/dirSize.zig @@ -3,14 +3,14 @@ const string = []const u8; const extras = @import("./lib.zig"); const fileSize = extras.fileSize; -pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.IterableDir) !u64 { +pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !u64 { var res: u64 = 0; var walk = try dir.walk(alloc); defer walk.deinit(); while (try walk.next()) |entry| { if (entry.kind != .file) continue; - res += try fileSize(dir.dir, entry.path); + res += try fileSize(dir, entry.path); } return res; } diff --git a/src/fileList.zig b/src/fileList.zig index f6e0961ffbd82b767cf425543b476e6ed7797fbe..357b861f49c0adedffaa9a7a47be28f85153b9e0 100644 --- a/src/fileList.zig +++ b/src/fileList.zig @@ -2,7 +2,7 @@ const std = @import("std"); const string = []const u8; const extras = @import("./lib.zig"); -pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.IterableDir) ![]string { +pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string { var list = std.ArrayList(string).init(alloc); defer list.deinit(); diff --git a/src/indexBufferT.zig b/src/indexBufferT.zig index 039dd8b5ad70094e0b2eb129100cd8fd1f188e0a..92afc431668651416c81d520402e5ea219ff9bfc 100644 --- a/src/indexBufferT.zig +++ b/src/indexBufferT.zig @@ -14,11 +14,11 @@ pub fn indexBufferT(bytes: [*]const u8, comptime T: type, endian: std.builtin.En test { const bytes = rawIntBytes(u32, 0x4e5a7da9); - try std.testing.expect(indexBufferT(&bytes, u16, .Big, 0, 2) == 0x4e5a); - try std.testing.expect(indexBufferT(&bytes, u16, .Big, 1, 2) == 0x7da9); + try std.testing.expect(indexBufferT(&bytes, u16, .big, 0, 2) == 0x4e5a); + try std.testing.expect(indexBufferT(&bytes, u16, .big, 1, 2) == 0x7da9); } test { const bytes = rawIntBytes(u32, 0x4e5a7da9); - try std.testing.expect(indexBufferT(&bytes, u16, .Little, 0, 2) == 0x5a4e); - try std.testing.expect(indexBufferT(&bytes, u16, .Little, 1, 2) == 0xa97d); + try std.testing.expect(indexBufferT(&bytes, u16, .little, 0, 2) == 0x5a4e); + try std.testing.expect(indexBufferT(&bytes, u16, .little, 1, 2) == 0xa97d); } diff --git a/src/isArrayOf.zig b/src/isArrayOf.zig index ceb24b5561d2e48e50cf473e3a48af787842b314..2630ecb2263dd22f3a3954d9e01f5bdc6e004e27 100644 --- a/src/isArrayOf.zig +++ b/src/isArrayOf.zig @@ -2,7 +2,7 @@ const std = @import("std"); const string = []const u8; const extras = @import("./lib.zig"); -pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { +pub fn isArrayOf(comptime T: type) fn (type) bool { const Closure = struct { pub fn trait(comptime C: type) bool { return switch (@typeInfo(C)) { diff --git a/src/lessThanSlice.zig b/src/lessThanSlice.zig index f5c65af0db094f96a3c9b0df03d8e0279ef364a0..d709a18b446aa7d1a301f7739fe2e856f3f4f710 100644 --- a/src/lessThanSlice.zig +++ b/src/lessThanSlice.zig @@ -3,7 +3,6 @@ const string = []const u8; const extras = @import("./lib.zig"); pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool { - comptime std.debug.assert(std.meta.trait.isSlice(T)); return struct { fn f(_: void, lhs: T, rhs: T) bool { const result = for (0..@min(lhs.len, rhs.len)) |i| { diff --git a/src/rawInt.zig b/src/rawInt.zig index 3ff83dff13bc2e072251ef39a7e90d5aa5bf5945..8cc1dd39bf5e509702eb5ff3151f0cde810f1ca6 100644 --- a/src/rawInt.zig +++ b/src/rawInt.zig @@ -7,8 +7,8 @@ const native_endian = builtin.target.cpu.arch.endian(); pub fn rawInt(comptime T: type, comptime literal: comptime_int) T { comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0); return switch (native_endian) { - .Little => @byteSwap(@as(T, literal)), - .Big => @compileError("unreachable"), + .little => @byteSwap(@as(T, literal)), + .big => @compileError("unreachable"), }; } diff --git a/src/readType.zig b/src/readType.zig index 58feaa94aa91746f4aa1dce73bd7721ed65a18ca..25d9872babf9bbf9d8f887bfc3e3937fd8246481 100644 --- a/src/readType.zig +++ b/src/readType.zig @@ -10,14 +10,14 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) ! return switch (@typeInfo(T)) { .Struct => |t| { switch (t.layout) { - .Auto, .Extern => { + .auto, .@"extern" => { var s: T = undefined; inline for (std.meta.fields(T)) |field| { @field(s, field.name) = try readType(reader, field.type, endian); } return s; }, - .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)), + .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)), } }, .Array => |t| { @@ -63,7 +63,7 @@ test { b: u8, c: u8, }; - const s = try readType(fba.reader(), S, .Big); + const s = try readType(fba.reader(), S, .big); try std.testing.expect(s.a == 0x4e5a); try std.testing.expect(s.b == 0x7d); try std.testing.expect(s.c == 0xa9); @@ -73,7 +73,7 @@ test { const bytes = rawIntBytes(u32, 0x4e5a7da9); var fba = std.io.fixedBufferStream(&bytes); const A = [2]u16; - const a = try readType(fba.reader(), A, .Big); + const a = try readType(fba.reader(), A, .big); try std.testing.expect(a[0] == 0x4e5a); try std.testing.expect(a[1] == 0x7da9); } @@ -87,7 +87,7 @@ test { c: u4, d: u8, }; - const s = try readType(fba.reader(), S, .Big); + const s = try readType(fba.reader(), S, .big); try std.testing.expect(s.a == 0x7da9); try std.testing.expect(s.b == 0xa); try std.testing.expect(s.c == 0x5);