authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-01 16:17:48 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-01 16:17:48 -07:00
log4d028531dd4a7fae86ffb95809302f25803785b8
tree761bb9834028dab8ce89cdcf78e361c02ea090c8
parentffadb1f7fe4ed9a716570196adeaad3bb63d8c89
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update to zig 0.15.2


7 files changed, 31 insertions(+), 33 deletions(-)

build.zig+6-4
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn build(b: *std.Build) void {3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});4 const target = b.standardTargetOptions(.{});
5 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;5 const mode = b.option(std.builtin.OptimizeMode, "mode", "") orelse .Debug;
6 const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false;6 const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false;
77
8 const mod = b.addModule("extras", .{8 const mod = b.addModule("extras", .{
...@@ -10,9 +10,11 @@ pub fn build(b: *std.Build) void {...@@ -10,9 +10,11 @@ pub fn build(b: *std.Build) void {
10 });10 });
1111
12 const tests = b.addTest(.{12 const tests = b.addTest(.{
13 .root_source_file = b.path("src/lib.zig"),13 .root_module = b.createModule(.{
14 .target = target,14 .root_source_file = b.path("src/lib.zig"),
15 .optimize = mode,15 .target = target,
16 .optimize = mode,
17 }),
16 });18 });
17 tests.root_module.addImport("extras", mod);19 tests.root_module.addImport("extras", mod);
18 tests.use_llvm = !disable_llvm;20 tests.use_llvm = !disable_llvm;
src/FixedMaxBuffer.zig+1-1
...@@ -10,7 +10,7 @@ pub fn FixedMaxBuffer(comptime max_len: usize) type {...@@ -10,7 +10,7 @@ pub fn FixedMaxBuffer(comptime max_len: usize) type {
10 pos: usize,10 pos: usize,
1111
12 const Self = @This();12 const Self = @This();
13 pub const Reader = std.io.Reader(*Self, error{}, read);13 pub const Reader = std.io.GenericReader(*Self, error{}, read);
1414
15 pub fn init(r: anytype, runtime_len: usize) !Self {15 pub fn init(r: anytype, runtime_len: usize) !Self {
16 var fmr = Self{16 var fmr = Self{
src/fmtByteCountIEC.zig+4-4
...@@ -12,14 +12,14 @@ fn formatByteCountIEC(bytes: u64, writer: *std.Io.Writer) !void {...@@ -12,14 +12,14 @@ fn formatByteCountIEC(bytes: u64, writer: *std.Io.Writer) !void {
12}12}
1313
14test {14test {
15 try std.testing.expectFmt("1 B", "{}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 0))});15 try std.testing.expectFmt("1 B", "{f}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 0))});
16}16}
17test {17test {
18 try std.testing.expectFmt("1.000 KB", "{}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 1))});18 try std.testing.expectFmt("1.000 KB", "{f}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 1))});
19}19}
20test {20test {
21 try std.testing.expectFmt("1.000 MB", "{}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 2))});21 try std.testing.expectFmt("1.000 MB", "{f}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 2))});
22}22}
23test {23test {
24 try std.testing.expectFmt("1.000 GB", "{}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 3))});24 try std.testing.expectFmt("1.000 GB", "{f}", .{fmtByteCountIEC(std.math.pow(u64, 1024, 3))});
25}25}
src/fmtReplacer.zig+3-7
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn fmtReplacer(bytes: string, from: u8, to: u8) std.fmt.Formatter(formatReplacer) {5pub fn fmtReplacer(bytes: string, from: u8, to: u8) std.fmt.Alt(FormatData, formatReplacer) {
6 return .{ .data = .{6 return .{ .data = .{
7 .bytes = bytes,7 .bytes = bytes,
8 .from = from,8 .from = from,
...@@ -18,12 +18,8 @@ const FormatData = struct {...@@ -18,12 +18,8 @@ const FormatData = struct {
1818
19fn formatReplacer(19fn formatReplacer(
20 self: FormatData,20 self: FormatData,
21 comptime fmt: []const u8,21 writer: *std.Io.Writer,
22 options: std.fmt.FormatOptions,
23 writer: anytype,
24) !void {22) !void {
25 _ = fmt;
26 _ = options;
27 for (self.bytes) |c| {23 for (self.bytes) |c| {
28 try writer.writeByte(if (c == self.from) self.to else @intCast(c));24 try writer.writeByte(if (c == self.from) self.to else @intCast(c));
29 }25 }
...@@ -32,5 +28,5 @@ fn formatReplacer(...@@ -32,5 +28,5 @@ fn formatReplacer(
32test {28test {
33 const in = "C:\\Program Files\\Custom Utilities\\StringFinder.exe";29 const in = "C:\\Program Files\\Custom Utilities\\StringFinder.exe";
34 const out = "C:/Program Files/Custom Utilities/StringFinder.exe";30 const out = "C:/Program Files/Custom Utilities/StringFinder.exe";
35 try std.testing.expectFmt(out, "{}", .{fmtReplacer(in, '\\', '/')});31 try std.testing.expectFmt(out, "{f}", .{fmtReplacer(in, '\\', '/')});
36}32}
src/mapBy.zig+2-2
...@@ -2,8 +2,8 @@ const std = @import("std");...@@ -2,8 +2,8 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn mapBy(allocator: std.mem.Allocator, slice: anytype, comptime field: std.meta.FieldEnum(std.meta.Elem(@TypeOf(slice)))) ![]std.meta.FieldType(std.meta.Elem(@TypeOf(slice)), field) {5pub fn mapBy(allocator: std.mem.Allocator, slice: anytype, comptime field: std.meta.FieldEnum(std.meta.Elem(@TypeOf(slice)))) ![]@FieldType(std.meta.Elem(@TypeOf(slice)), @tagName(field)) {
6 const newslice = try allocator.alloc(std.meta.FieldType(std.meta.Elem(@TypeOf(slice)), field), slice.len);6 const newslice = try allocator.alloc(@FieldType(std.meta.Elem(@TypeOf(slice)), @tagName(field)), slice.len);
7 for (newslice, slice) |*i, j| i.* = @field(j, @tagName(field));7 for (newslice, slice) |*i, j| i.* = @field(j, @tagName(field));
8 return newslice;8 return newslice;
9}9}
src/pipe.zig+3-3
...@@ -15,8 +15,8 @@ test {...@@ -15,8 +15,8 @@ test {
15 const bytes = "abcdefghijklmnopqrstuvwxyz".*;15 const bytes = "abcdefghijklmnopqrstuvwxyz".*;
16 var fba = std.io.fixedBufferStream(&bytes);16 var fba = std.io.fixedBufferStream(&bytes);
17 const allocator = std.testing.allocator;17 const allocator = std.testing.allocator;
18 var list = std.ArrayList(u8).init(allocator);18 var list = std.Io.Writer.Allocating.init(allocator);
19 defer list.deinit();19 defer list.deinit();
20 try pipe(fba.reader(), list.writer());20 try pipe(fba.reader(), &list.writer);
21 try std.testing.expect(std.mem.eql(u8, &bytes, list.items));21 try std.testing.expect(std.mem.eql(u8, &bytes, list.written()));
22}22}
src/reduceNumber.zig+12-12
...@@ -21,29 +21,29 @@ pub fn reduceNumber(writer: anytype, input: u64, comptime unit: u64, comptime ba...@@ -21,29 +21,29 @@ pub fn reduceNumber(writer: anytype, input: u64, comptime unit: u64, comptime ba
2121
22test {22test {
23 const allocator = std.testing.allocator;23 const allocator = std.testing.allocator;
24 var list = std.ArrayList(u8).init(allocator);24 var list = std.Io.Writer.Allocating.init(allocator);
25 defer list.deinit();25 defer list.deinit();
26 try reduceNumber(list.writer(), 1, 60, "s", "mh");26 try reduceNumber(&list.writer, 1, 60, "s", "mh");
27 try std.testing.expect(std.mem.eql(u8, list.items, "1 s"));27 try std.testing.expect(std.mem.eql(u8, list.written(), "1 s"));
28}28}
29test {29test {
30 const allocator = std.testing.allocator;30 const allocator = std.testing.allocator;
31 var list = std.ArrayList(u8).init(allocator);31 var list = std.Io.Writer.Allocating.init(allocator);
32 defer list.deinit();32 defer list.deinit();
33 try reduceNumber(list.writer(), 60, 60, "s", "mh");33 try reduceNumber(&list.writer, 60, 60, "s", "mh");
34 try std.testing.expect(std.mem.eql(u8, list.items, "1.000 ms"));34 try std.testing.expect(std.mem.eql(u8, list.written(), "1.000 ms"));
35}35}
36test {36test {
37 const allocator = std.testing.allocator;37 const allocator = std.testing.allocator;
38 var list = std.ArrayList(u8).init(allocator);38 var list = std.Io.Writer.Allocating.init(allocator);
39 defer list.deinit();39 defer list.deinit();
40 try reduceNumber(list.writer(), 3600, 60, "s", "mh");40 try reduceNumber(&list.writer, 3600, 60, "s", "mh");
41 try std.testing.expect(std.mem.eql(u8, list.items, "1.000 hs"));41 try std.testing.expect(std.mem.eql(u8, list.written(), "1.000 hs"));
42}42}
43test {43test {
44 const allocator = std.testing.allocator;44 const allocator = std.testing.allocator;
45 var list = std.ArrayList(u8).init(allocator);45 var list = std.Io.Writer.Allocating.init(allocator);
46 defer list.deinit();46 defer list.deinit();
47 try reduceNumber(list.writer(), 216000, 60, "s", "mh");47 try reduceNumber(&list.writer, 216000, 60, "s", "mh");
48 try std.testing.expect(std.mem.eql(u8, list.items, "60.000 hs"));48 try std.testing.expect(std.mem.eql(u8, list.written(), "60.000 hs"));
49}49}