| ... | @@ -107,14 +107,10 @@ pub const Guid = extern struct { | ... | @@ -107,14 +107,10 @@ pub const Guid = extern struct { |
| 107 | | 107 | |
| 108 | /// Format GUID into hexadecimal lowercase xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format | 108 | /// Format GUID into hexadecimal lowercase xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format |
| 109 | pub fn format(self: Guid, writer: *std.Io.Writer) std.Io.Writer.Error!void { | 109 | pub fn format(self: Guid, writer: *std.Io.Writer) std.Io.Writer.Error!void { |
| 110 | const time_low = @byteSwap(self.time_low); | | |
| 111 | const time_mid = @byteSwap(self.time_mid); | | |
| 112 | const time_high_and_version = @byteSwap(self.time_high_and_version); | | |
| 113 | | | |
| 114 | return writer.print("{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x}", .{ | 110 | return writer.print("{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x}", .{ |
| 115 | time_low, | 111 | self.time_low, |
| 116 | time_mid, | 112 | self.time_mid, |
| 117 | time_high_and_version, | 113 | self.time_high_and_version, |
| 118 | self.clock_seq_high_and_reserved, | 114 | self.clock_seq_high_and_reserved, |
| 119 | self.clock_seq_low, | 115 | self.clock_seq_low, |
| 120 | self.node, | 116 | self.node, |
| ... | @@ -225,10 +221,10 @@ test "GUID formatting" { | ... | @@ -225,10 +221,10 @@ test "GUID formatting" { |
| 225 | const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; | 221 | const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 }; |
| 226 | const guid: Guid = @bitCast(bytes); | 222 | const guid: Guid = @bitCast(bytes); |
| 227 | | 223 | |
| 228 | const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid}); | 224 | const str = try std.fmt.allocPrint(std.testing.allocator, "{f}", .{guid}); |
| 229 | defer std.testing.allocator.free(str); | 225 | defer std.testing.allocator.free(str); |
| 230 | | 226 | |
| 231 | try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287")); | 227 | try std.testing.expectEqualStrings(str, "32cb3c89-8080-427c-ba13-5049873bc287"); |
| 232 | } | 228 | } |
| 233 | | 229 | |
| 234 | test { | 230 | test { |