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...@@ -17,7 +17,7 @@ pub fn reduceNumber(alloc: std.mem.Allocator, input: u64, comptime unit: u64, co
17 div *= unit;17 div *= unit;
18 exp += 1;18 exp += 1;
19 }19 }
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 });
21}21}
2222
23pub fn addSentinel(alloc: std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T {23pub 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 {...@@ -115,7 +115,7 @@ pub fn sliceToInt(comptime T: type, comptime E: type, slice: []const E) !T {
115115
116 var n: T = 0;116 var n: T = 0;
117 for (slice, 0..) |item, i| {117 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));
119 n = n | (@as(T, item) << shift);119 n = n | (@as(T, item) << shift);
120 }120 }
121 return n;121 return n;
...@@ -209,12 +209,12 @@ pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {...@@ -209,12 +209,12 @@ pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {
209209
210pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T {210pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T {
211 if (@alignOf(T) == 0) @compileError(@typeName(T));211 if (@alignOf(T) == 0) @compileError(@typeName(T));
212 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));212 return @ptrCast(@alignCast(ptr));
213}213}
214214
215pub fn ptrCastConst(comptime T: type, ptr: *const anyopaque) *const T {215pub fn ptrCastConst(comptime T: type, ptr: *const anyopaque) *const T {
216 if (@alignOf(T) == 0) @compileError(@typeName(T));216 if (@alignOf(T) == 0) @compileError(@typeName(T));
217 return @ptrCast(*const T, @alignCast(@alignOf(T), ptr));217 return @ptrCast(@alignCast(ptr));
218}218}
219219
220pub fn sortBy(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T)) void {220pub 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...@@ -290,7 +290,7 @@ fn formatReplacer(self: ReplacerData, comptime fmt: []const u8, options: std.fmt
290 _ = fmt;290 _ = fmt;
291 _ = options;291 _ = options;
292 for (self.bytes) |c| {292 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));
294 }294 }
295}295}
296296
...@@ -301,11 +301,11 @@ pub fn randomBytes(comptime len: usize) [len]u8 {...@@ -301,11 +301,11 @@ pub fn randomBytes(comptime len: usize) [len]u8 {
301}301}
302302
303pub fn writeEnumBig(writer: anytype, comptime E: type, value: E) !void {303pub 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));
305}305}
306306
307pub fn readEnumBig(reader: anytype, comptime E: type) !E {307pub 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));
309}309}
310310
311pub fn readExpected(reader: anytype, expected: []const u8) !bool {311pub fn readExpected(reader: anytype, expected: []const u8) !bool {
...@@ -349,7 +349,7 @@ pub fn FixedMaxBuffer(comptime max_len: usize) type {...@@ -349,7 +349,7 @@ pub fn FixedMaxBuffer(comptime max_len: usize) type {
349349
350 fn read(self: *Self, dest: []u8) error{}!usize {350 fn read(self: *Self, dest: []u8) error{}!usize {
351 const buf = self.buf[0..self.len];351 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);
353 const end = self.pos + size;353 const end = self.pos + size;
354 std.mem.copy(u8, dest[0..size], buf[self.pos..end]);354 std.mem.copy(u8, dest[0..size], buf[self.pos..end]);
355 self.pos = end;355 self.pos = end;
...@@ -387,7 +387,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !...@@ -387,7 +387,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
387 }387 }
388 return s;388 return s;
389 },389 },
390 .Packed => return @bitCast(T, try readType(reader, t.backing_integer.?, endian)),390 .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
391 }391 }
392 },392 },
393 .Array => |t| {393 .Array => |t| {
...@@ -398,7 +398,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !...@@ -398,7 +398,7 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
398 return s;398 return s;
399 },399 },
400 .Int => try reader.readInt(T, endian),400 .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)),
402 else => |e| @compileError(@tagName(e)),402 else => |e| @compileError(@tagName(e)),
403 };403 };
404}404}
...@@ -448,9 +448,9 @@ pub fn is(a: anytype, b: @TypeOf(a)) bool {...@@ -448,9 +448,9 @@ pub fn is(a: anytype, b: @TypeOf(a)) bool {
448/// Allows u32 + i16 to work448/// Allows u32 + i16 to work
449pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) {449pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) {
450 if (b >= 0) {450 if (b >= 0) {
451 return a + @intCast(@TypeOf(a), b);451 return a + @as(@TypeOf(a), @intCast(b));
452 }452 }
453 return a - @intCast(@TypeOf(a), -b);453 return a - @as(@TypeOf(a), @intCast(-b));
454}454}
455455
456pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 {456pub 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 {...@@ -510,9 +510,8 @@ pub fn assertLog(ok: bool, comptime message: string, args: anytype) void {
510 if (!ok) unreachable; // assertion failure510 if (!ok) unreachable; // assertion failure
511}511}
512512
513pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.ValueTree {513pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.Parsed(std.json.Value) {
514 var p = std.json.Parser.init(alloc, .alloc_always);514 return std.json.parseFromSlice(std.json.Value, alloc, input, .{});
515 return try p.parse(input);
516}515}
517516
518pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {517pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {