| ... | @@ -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 | } |
| 22 | | 22 | |
| 23 | pub fn addSentinel(alloc: std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T { | 23 | pub 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 { |
| 115 | | 115 | |
| 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 { |
| 209 | | 209 | |
| 210 | pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T { | 210 | pub 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 | } |
| 214 | | 214 | |
| 215 | pub fn ptrCastConst(comptime T: type, ptr: *const anyopaque) *const T { | 215 | pub 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 | } |
| 219 | | 219 | |
| 220 | pub fn sortBy(comptime T: type, items: []T, comptime field: std.meta.FieldEnum(T)) void { | 220 | pub 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 | } |
| 296 | | 296 | |
| ... | @@ -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 | } |
| 302 | | 302 | |
| 303 | pub fn writeEnumBig(writer: anytype, comptime E: type, value: E) !void { | 303 | pub 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 | } |
| 306 | | 306 | |
| 307 | pub fn readEnumBig(reader: anytype, comptime E: type) !E { | 307 | pub 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 | } |
| 310 | | 310 | |
| 311 | pub fn readExpected(reader: anytype, expected: []const u8) !bool { | 311 | pub 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 { |
| 349 | | 349 | |
| 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 work | 448 | /// Allows u32 + i16 to work |
| 449 | pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) { | 449 | pub 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 | } |
| 455 | | 455 | |
| 456 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { | 456 | pub 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 failure | 510 | if (!ok) unreachable; // assertion failure |
| 511 | } | 511 | } |
| 512 | | 512 | |
| 513 | pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.ValueTree { | 513 | pub 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 | } |
| 517 | | 516 | |
| 518 | pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { | 517 | pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { |