| ... | ... | @@ -426,29 +426,27 @@ pub const Version = struct { |
| 426 | 426 | pub fn parse(text: []const u8) !Version { |
| 427 | 427 | var it = std.mem.separate(text, "."); |
| 428 | 428 | return Version{ |
| 429 | | .major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10), |
| 430 | | .minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10), |
| 431 | | .patch = try std.fmt.parseInt(u32, it.next() orelse "0", 10), |
| 429 | .major = try std.fmtstream.parseInt(u32, it.next() orelse return error.InvalidVersion, 10), |
| 430 | .minor = try std.fmtstream.parseInt(u32, it.next() orelse "0", 10), |
| 431 | .patch = try std.fmtstream.parseInt(u32, it.next() orelse "0", 10), |
| 432 | 432 | }; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | pub fn format( |
| 436 | 436 | self: Version, |
| 437 | 437 | comptime fmt: []const u8, |
| 438 | | options: std.fmt.FormatOptions, |
| 439 | | context: var, |
| 440 | | comptime Error: type, |
| 441 | | comptime output: fn (@TypeOf(context), []const u8) Error!void, |
| 442 | | ) Error!void { |
| 438 | options: std.fmtstream.FormatOptions, |
| 439 | out_stream: var, |
| 440 | ) !void { |
| 443 | 441 | if (fmt.len == 0) { |
| 444 | 442 | if (self.patch == 0) { |
| 445 | 443 | if (self.minor == 0) { |
| 446 | | return std.fmt.format(context, Error, output, "{}", .{self.major}); |
| 444 | return std.fmtstream.format(out_stream, "{}", .{self.major}); |
| 447 | 445 | } else { |
| 448 | | return std.fmt.format(context, Error, output, "{}.{}", .{ self.major, self.minor }); |
| 446 | return std.fmtstream.format(out_stream, "{}.{}", .{ self.major, self.minor }); |
| 449 | 447 | } |
| 450 | 448 | } else { |
| 451 | | return std.fmt.format(context, Error, output, "{}.{}.{}", .{ self.major, self.minor, self.patch }); |
| 449 | return std.fmtstream.format(out_stream, "{}.{}.{}", .{ self.major, self.minor, self.patch }); |
| 452 | 450 | } |
| 453 | 451 | } else { |
| 454 | 452 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |