authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-04 01:18:59 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-04 01:18:59 -07:00
log8628846c832086d97f28c54eab157cda389c319a
treee30e394c62fd88ec53b0f18d3cf8c08889921c06
parent5bb45177a8961764ea4e0949f24513afa0bd1374

update to zig 0.11.0


1 files changed, 14 insertions(+), 15 deletions(-)

src/lib.zig+14-15
......@@ -17,7 +17,7 @@ pub fn reduceNumber(alloc: std.mem.Allocator, input: u64, comptime unit: u64, co
1717 div *= unit;
1818 exp += 1;
1919 }
20 return try std.fmt.allocPrint(alloc, "{d:.3} {s}{s}", .{ @intToFloat(f64, input) / @intToFloat(f64, div), prefixes[exp .. exp + 1], base });
20 return try std.fmt.allocPrint(alloc, "{d:.3} {s}{s}", .{ @as(f64, @floatFromInt(input)) / @as(f64, @floatFromInt(div)), prefixes[exp .. exp + 1], base });
2121}
2222
2323pub fn addSentinel(alloc: std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T {
......@@ -115,7 +115,7 @@ pub fn sliceToInt(comptime T: type, comptime E: type, slice: []const E) !T {
115115
116116 var n: T = 0;
117117 for (slice, 0..) |item, i| {
118 const shift = @intCast(std.math.Log2Int(T), b * (slice.len - 1 - i));
118 const shift: std.math.Log2Int(T) = @intCast(b * (slice.len - 1 - i));
119119 n = n | (@as(T, item) << shift);
120120 }
121121 return n;
......@@ -209,12 +209,12 @@ pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {
209209
210210pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T {
211211 if (@alignOf(T) == 0) @compileError(@typeName(T));
212 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));
212 return @ptrCast(@alignCast(ptr));
213213}
214214
215215pub fn ptrCastConst(comptime T: type, ptr: *const anyopaque) *const T {
216216 if (@alignOf(T) == 0) @compileError(@typeName(T));
217 return @ptrCast(*const T, @alignCast(@alignOf(T), ptr));
217 return @ptrCast(@alignCast(ptr));
218218}
219219
220220pub fn sortBy(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T)) void {
......@@ -290,7 +290,7 @@ fn formatReplacer(self: ReplacerData, comptime fmt: []const u8, options: std.fmt
290290 _ = fmt;
291291 _ = options;
292292 for (self.bytes) |c| {
293 try writer.writeByte(if (c == self.from) self.to else @intCast(u8, c));
293 try writer.writeByte(if (c == self.from) self.to else @intCast(c));
294294 }
295295}
296296
......@@ -301,11 +301,11 @@ pub fn randomBytes(comptime len: usize) [len]u8 {
301301}
302302
303303pub fn writeEnumBig(writer: anytype, comptime E: type, value: E) !void {
304 try writer.writeIntBig(@typeInfo(E).Enum.tag_type, @enumToInt(value));
304 try writer.writeIntBig(@typeInfo(E).Enum.tag_type, @intFromEnum(value));
305305}
306306
307307pub fn readEnumBig(reader: anytype, comptime E: type) !E {
308 return @intToEnum(E, try reader.readIntBig(@typeInfo(E).Enum.tag_type));
308 return @enumFromInt(try reader.readIntBig(@typeInfo(E).Enum.tag_type));
309309}
310310
311311pub fn readExpected(reader: anytype, expected: []const u8) !bool {
......@@ -349,7 +349,7 @@ pub fn FixedMaxBuffer(comptime max_len: usize) type {
349349
350350 fn read(self: *Self, dest: []u8) error{}!usize {
351351 const buf = self.buf[0..self.len];
352 const size = std.math.min(dest.len, buf.len - self.pos);
352 const size = @min(dest.len, buf.len - self.pos);
353353 const end = self.pos + size;
354354 std.mem.copy(u8, dest[0..size], buf[self.pos..end]);
355355 self.pos = end;
......@@ -387,7 +387,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
387387 }
388388 return s;
389389 },
390 .Packed => return @bitCast(T, try readType(reader, t.backing_integer.?, endian)),
390 .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
391391 }
392392 },
393393 .Array => |t| {
......@@ -398,7 +398,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
398398 return s;
399399 },
400400 .Int => try reader.readInt(T, endian),
401 .Enum => |t| @intToEnum(T, try readType(reader, t.tag_type, endian)),
401 .Enum => |t| @enumFromInt(try readType(reader, t.tag_type, endian)),
402402 else => |e| @compileError(@tagName(e)),
403403 };
404404}
......@@ -448,9 +448,9 @@ pub fn is(a: anytype, b: @TypeOf(a)) bool {
448448/// Allows u32 + i16 to work
449449pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) {
450450 if (b >= 0) {
451 return a + @intCast(@TypeOf(a), b);
451 return a + @as(@TypeOf(a), @intCast(b));
452452 }
453 return a - @intCast(@TypeOf(a), -b);
453 return a - @as(@TypeOf(a), @intCast(-b));
454454}
455455
456456pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 {
......@@ -510,9 +510,8 @@ pub fn assertLog(ok: bool, comptime message: string, args: anytype) void {
510510 if (!ok) unreachable; // assertion failure
511511}
512512
513pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.ValueTree {
514 var p = std.json.Parser.init(alloc, .alloc_always);
515 return try p.parse(input);
513pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.Parsed(std.json.Value) {
514 return std.json.parseFromSlice(std.json.Value, alloc, input, .{});
516515}
517516
518517pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {