| author | |
| committer | |
| log | 3dcc531937b58d787e183c25bad535c91bab1f7d |
| tree | f1cdef2dae2fc1d9035a019e70f6cb21123a4015 |
| parent | 0332280cf015fe079b771cd3f29a7408c1f1e71f |
13 files changed, 25 insertions(+), 26 deletions(-)
build.zig+2-2| ... | ... | @@ -1,12 +1,12 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn build(b: *std.build.Builder) void { | |
| 3 | pub fn build(b: *std.Build) void { | |
| 4 | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | 5 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; |
| 6 | 6 | |
| 7 | 7 | _ = b.addModule( |
| 8 | 8 | "extras", |
| 9 | .{ .source_file = .{ .path = "src/lib.zig" } }, | |
| 9 | .{ .root_source_file = .{ .path = "src/lib.zig" } }, | |
| 10 | 10 | ); |
| 11 | 11 | |
| 12 | 12 | const exe_unit_tests = b.addTest(.{ |
src/BufIndexer.zig+4-4| ... | ... | @@ -27,20 +27,20 @@ pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type { |
| 27 | 27 | |
| 28 | 28 | test { |
| 29 | 29 | const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); |
| 30 | const bindex = BufIndexer(u64, .Big).init(&bytes, 1); | |
| 30 | const bindex = BufIndexer(u64, .big).init(&bytes, 1); | |
| 31 | 31 | try std.testing.expect(bindex.at(0) == 0x4e5a7da9f3f1d132); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test { |
| 35 | 35 | const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); |
| 36 | const bindex = BufIndexer(u32, .Big).init(&bytes, 2); | |
| 36 | const bindex = BufIndexer(u32, .big).init(&bytes, 2); | |
| 37 | 37 | try std.testing.expect(bindex.at(0) == 0x4e5a7da9); |
| 38 | 38 | try std.testing.expect(bindex.at(1) == 0xf3f1d132); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | test { |
| 42 | 42 | const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); |
| 43 | const bindex = BufIndexer(u16, .Big).init(&bytes, 4); | |
| 43 | const bindex = BufIndexer(u16, .big).init(&bytes, 4); | |
| 44 | 44 | try std.testing.expect(bindex.at(0) == 0x4e5a); |
| 45 | 45 | try std.testing.expect(bindex.at(1) == 0x7da9); |
| 46 | 46 | try std.testing.expect(bindex.at(2) == 0xf3f1); |
| ... | ... | @@ -49,7 +49,7 @@ test { |
| 49 | 49 | |
| 50 | 50 | test { |
| 51 | 51 | const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132); |
| 52 | const bindex = BufIndexer(u8, .Big).init(&bytes, 8); | |
| 52 | const bindex = BufIndexer(u8, .big).init(&bytes, 8); | |
| 53 | 53 | try std.testing.expect(bindex.at(0) == 0x4e); |
| 54 | 54 | try std.testing.expect(bindex.at(1) == 0x5a); |
| 55 | 55 | try std.testing.expect(bindex.at(2) == 0x7d); |
src/FieldUnion.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ pub fn FieldUnion(comptime T: type) type { |
| 15 | 15 | }; |
| 16 | 16 | } |
| 17 | 17 | return @Type(std.builtin.Type{ .Union = .{ |
| 18 | .layout = .Auto, | |
| 18 | .layout = .auto, | |
| 19 | 19 | .tag_type = std.meta.FieldEnum(T), |
| 20 | 20 | .fields = &fields, |
| 21 | 21 | .decls = &.{}, |
src/Partial.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ pub fn Partial(comptime T: type) type { |
| 18 | 18 | }; |
| 19 | 19 | } |
| 20 | 20 | return @Type(@unionInit(std.builtin.Type, "Struct", .{ |
| 21 | .layout = .Auto, | |
| 21 | .layout = .auto, | |
| 22 | 22 | .backing_integer = null, |
| 23 | 23 | .fields = &fields_after, |
| 24 | 24 | .decls = &.{}, |
src/base64DecodeAlloc.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const extras = @import("./lib.zig"); |
| 4 | 4 | |
| 5 | 5 | pub fn base64DecodeAlloc(alloc: std.mem.Allocator, input: string) !string { |
| 6 | 6 | const base64 = std.base64.standard.Decoder; |
| 7 | var buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input)); | |
| 7 | const buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input)); | |
| 8 | 8 | try base64.decode(buf, input); |
| 9 | 9 | return buf; |
| 10 | 10 | } |
src/base64EncodeAlloc.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const extras = @import("./lib.zig"); |
| 4 | 4 | |
| 5 | 5 | pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string { |
| 6 | 6 | const base64 = std.base64.standard.Encoder; |
| 7 | var buf = try alloc.alloc(u8, base64.calcSize(input.len)); | |
| 7 | const buf = try alloc.alloc(u8, base64.calcSize(input.len)); | |
| 8 | 8 | return base64.encode(buf, input); |
| 9 | 9 | } |
| 10 | 10 |
src/dirSize.zig+2-2| ... | ... | @@ -3,14 +3,14 @@ const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | 4 | const fileSize = extras.fileSize; |
| 5 | 5 | |
| 6 | pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.IterableDir) !u64 { | |
| 6 | pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !u64 { | |
| 7 | 7 | var res: u64 = 0; |
| 8 | 8 | |
| 9 | 9 | var walk = try dir.walk(alloc); |
| 10 | 10 | defer walk.deinit(); |
| 11 | 11 | while (try walk.next()) |entry| { |
| 12 | 12 | if (entry.kind != .file) continue; |
| 13 | res += try fileSize(dir.dir, entry.path); | |
| 13 | res += try fileSize(dir, entry.path); | |
| 14 | 14 | } |
| 15 | 15 | return res; |
| 16 | 16 | } |
src/fileList.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | 4 | |
| 5 | pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.IterableDir) ![]string { | |
| 5 | pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string { | |
| 6 | 6 | var list = std.ArrayList(string).init(alloc); |
| 7 | 7 | defer list.deinit(); |
| 8 | 8 |
src/indexBufferT.zig+4-4| ... | ... | @@ -14,11 +14,11 @@ pub fn indexBufferT(bytes: [*]const u8, comptime T: type, endian: std.builtin.En |
| 14 | 14 | |
| 15 | 15 | test { |
| 16 | 16 | const bytes = rawIntBytes(u32, 0x4e5a7da9); |
| 17 | try std.testing.expect(indexBufferT(&bytes, u16, .Big, 0, 2) == 0x4e5a); | |
| 18 | try std.testing.expect(indexBufferT(&bytes, u16, .Big, 1, 2) == 0x7da9); | |
| 17 | try std.testing.expect(indexBufferT(&bytes, u16, .big, 0, 2) == 0x4e5a); | |
| 18 | try std.testing.expect(indexBufferT(&bytes, u16, .big, 1, 2) == 0x7da9); | |
| 19 | 19 | } |
| 20 | 20 | test { |
| 21 | 21 | const bytes = rawIntBytes(u32, 0x4e5a7da9); |
| 22 | try std.testing.expect(indexBufferT(&bytes, u16, .Little, 0, 2) == 0x5a4e); | |
| 23 | try std.testing.expect(indexBufferT(&bytes, u16, .Little, 1, 2) == 0xa97d); | |
| 22 | try std.testing.expect(indexBufferT(&bytes, u16, .little, 0, 2) == 0x5a4e); | |
| 23 | try std.testing.expect(indexBufferT(&bytes, u16, .little, 1, 2) == 0xa97d); | |
| 24 | 24 | } |
src/isArrayOf.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | 4 | |
| 5 | pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { | |
| 5 | pub fn isArrayOf(comptime T: type) fn (type) bool { | |
| 6 | 6 | const Closure = struct { |
| 7 | 7 | pub fn trait(comptime C: type) bool { |
| 8 | 8 | return switch (@typeInfo(C)) { |
src/lessThanSlice.zig-1| ... | ... | @@ -3,7 +3,6 @@ const string = []const u8; |
| 3 | 3 | const extras = @import("./lib.zig"); |
| 4 | 4 | |
| 5 | 5 | pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool { |
| 6 | comptime std.debug.assert(std.meta.trait.isSlice(T)); | |
| 7 | 6 | return struct { |
| 8 | 7 | fn f(_: void, lhs: T, rhs: T) bool { |
| 9 | 8 | const result = for (0..@min(lhs.len, rhs.len)) |i| { |
src/rawInt.zig+2-2| ... | ... | @@ -7,8 +7,8 @@ const native_endian = builtin.target.cpu.arch.endian(); |
| 7 | 7 | pub fn rawInt(comptime T: type, comptime literal: comptime_int) T { |
| 8 | 8 | comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0); |
| 9 | 9 | return switch (native_endian) { |
| 10 | .Little => @byteSwap(@as(T, literal)), | |
| 11 | .Big => @compileError("unreachable"), | |
| 10 | .little => @byteSwap(@as(T, literal)), | |
| 11 | .big => @compileError("unreachable"), | |
| 12 | 12 | }; |
| 13 | 13 | } |
| 14 | 14 |
src/readType.zig+5-5| ... | ... | @@ -10,14 +10,14 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) ! |
| 10 | 10 | return switch (@typeInfo(T)) { |
| 11 | 11 | .Struct => |t| { |
| 12 | 12 | switch (t.layout) { |
| 13 | .Auto, .Extern => { | |
| 13 | .auto, .@"extern" => { | |
| 14 | 14 | var s: T = undefined; |
| 15 | 15 | inline for (std.meta.fields(T)) |field| { |
| 16 | 16 | @field(s, field.name) = try readType(reader, field.type, endian); |
| 17 | 17 | } |
| 18 | 18 | return s; |
| 19 | 19 | }, |
| 20 | .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)), | |
| 20 | .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)), | |
| 21 | 21 | } |
| 22 | 22 | }, |
| 23 | 23 | .Array => |t| { |
| ... | ... | @@ -63,7 +63,7 @@ test { |
| 63 | 63 | b: u8, |
| 64 | 64 | c: u8, |
| 65 | 65 | }; |
| 66 | const s = try readType(fba.reader(), S, .Big); | |
| 66 | const s = try readType(fba.reader(), S, .big); | |
| 67 | 67 | try std.testing.expect(s.a == 0x4e5a); |
| 68 | 68 | try std.testing.expect(s.b == 0x7d); |
| 69 | 69 | try std.testing.expect(s.c == 0xa9); |
| ... | ... | @@ -73,7 +73,7 @@ test { |
| 73 | 73 | const bytes = rawIntBytes(u32, 0x4e5a7da9); |
| 74 | 74 | var fba = std.io.fixedBufferStream(&bytes); |
| 75 | 75 | const A = [2]u16; |
| 76 | const a = try readType(fba.reader(), A, .Big); | |
| 76 | const a = try readType(fba.reader(), A, .big); | |
| 77 | 77 | try std.testing.expect(a[0] == 0x4e5a); |
| 78 | 78 | try std.testing.expect(a[1] == 0x7da9); |
| 79 | 79 | } |
| ... | ... | @@ -87,7 +87,7 @@ test { |
| 87 | 87 | c: u4, |
| 88 | 88 | d: u8, |
| 89 | 89 | }; |
| 90 | const s = try readType(fba.reader(), S, .Big); | |
| 90 | const s = try readType(fba.reader(), S, .big); | |
| 91 | 91 | try std.testing.expect(s.a == 0x7da9); |
| 92 | 92 | try std.testing.expect(s.b == 0xa); |
| 93 | 93 | try std.testing.expect(s.c == 0x5); |