From 945510cc585daaad62c83f485f80505480cbc9be Mon Sep 17 00:00:00 2001 From: "David P. Sugar" Date: Fri, 7 Jul 2023 20:09:30 +0200 Subject: [PATCH] minor fixes --- README.md | 2 +- examples/uuid_v4.zig | 2 +- examples/uuid_v7.zig | 4 ++-- src/urn.zig | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0618cfc..61dec3c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ const uuid = @import("uuid-zig"); const id = uuid.v7.new(); -const urn = try uuid.urn.serialize(id); +const urn = uuid.urn.serialize(id); ``` You can also parse URNs (UUID strings): diff --git a/examples/uuid_v4.zig b/examples/uuid_v4.zig index 428814f..f3bddb6 100644 --- a/examples/uuid_v4.zig +++ b/examples/uuid_v4.zig @@ -4,7 +4,7 @@ const uuid = @import("uuid-zig"); pub fn main() !void { const id = uuid.v4.new(); - const urn = try uuid.urn.serialize(id); + const urn = uuid.urn.serialize(id); const stdout = std.io.getStdOut().writer(); try stdout.print("v4: {s}\n", .{&urn}); diff --git a/examples/uuid_v7.zig b/examples/uuid_v7.zig index 7faaf3c..6c49ebf 100644 --- a/examples/uuid_v7.zig +++ b/examples/uuid_v7.zig @@ -5,8 +5,8 @@ pub fn main() !void { const id1 = uuid.v7.new(); const id2 = uuid.v7.new(); - const urn1 = try uuid.urn.serialize(id1); - const urn2 = try uuid.urn.serialize(id2); + const urn1 = uuid.urn.serialize(id1); + const urn2 = uuid.urn.serialize(id2); const stdout = std.io.getStdOut().writer(); try stdout.print("v7: {s}\n", .{urn1}); diff --git a/src/urn.zig b/src/urn.zig index 5bf1aaa..5c1a71f 100644 --- a/src/urn.zig +++ b/src/urn.zig @@ -12,16 +12,16 @@ pub const Urn = [36]u8; /// /// The caller is responsible for deallocating the string returned /// by this function. -pub fn serialize(uuid: Uuid) !Urn { +pub fn serialize(uuid: Uuid) Urn { var urn: Urn = undefined; - _ = try std.fmt.bufPrint(&urn, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{ + _ = std.fmt.bufPrint(&urn, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{ core.getTimeLow(uuid), core.getTimeMid(uuid), core.getTimeHiAndVersion(uuid), core.getClockSeqHiAndReserved(uuid), core.getClockSeqLow(uuid), core.getNode(uuid), - }); + }) catch unreachable; return urn; } @@ -66,7 +66,7 @@ pub fn deserialize(s: []const u8) !Uuid { test "uuid to urn" { const uuid1: Uuid = 0xffeeddccbbaa99887766554433221100; - const urn1 = try serialize(uuid1); + const urn1 = serialize(uuid1); try std.testing.expectEqualSlices(u8, "00112233-4455-6677-8899-aabbccddeeff", urn1[0..]); } @@ -79,7 +79,7 @@ test "urn tu uudi" { test "urn full circle" { const urn1 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"; const uuid = try deserialize(urn1); - const urn_new = try serialize(uuid); + const urn_new = serialize(uuid); try std.testing.expectEqualStrings(urn1, &urn_new); }