| ... | ... | @@ -19,14 +19,14 @@ pub const Factory = struct { |
| 19 | 19 | pub fn newULID(self: Factory) ULID { |
| 20 | 20 | const now = std.time.milliTimestamp(); |
| 21 | 21 | return ULID{ |
| 22 | | .timestamp = std.math.cast(u48, now - self.epoch) catch @panic("time.milliTimestamp() is higher than 281474976710655"), |
| 22 | .timestamp = std.math.cast(u48, now - self.epoch) orelse @panic("time.milliTimestamp() is higher than 281474976710655"), |
| 23 | 23 | .randomnes = self.rand.int(u80), |
| 24 | 24 | }; |
| 25 | 25 | } |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | 28 | /// 01AN4Z07BY 79KA1307SR9X4MV3 |
| 29 | | /// |
| 29 | /// |
| 30 | 30 | /// |----------| |----------------| |
| 31 | 31 | /// Timestamp Randomness |
| 32 | 32 | /// 48bits 80bits |
| ... | ... | @@ -41,7 +41,7 @@ pub const ULID = struct { |
| 41 | 41 | pub fn parse(alloc: std.mem.Allocator, value: BaseType) !ULID { |
| 42 | 42 | if (value.len != 26) return error.Ulid; |
| 43 | 43 | return ULID{ |
| 44 | | .timestamp = try std.math.cast(u48, try extras.sliceToInt(u50, u5, try base32.decode(alloc, value[0..10]))), |
| 44 | .timestamp = std.math.cast(u48, try extras.sliceToInt(u50, u5, try base32.decode(alloc, value[0..10]))) orelse return error.Ulid, |
| 45 | 45 | .randomnes = try extras.sliceToInt(u80, u5, try base32.decode(alloc, value[10..26])), |
| 46 | 46 | }; |
| 47 | 47 | } |