summaryrefslogtreecommitdiff
path: root/core/walk.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/walk.zig')
-rw-r--r--core/walk.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/walk.zig b/core/walk.zig
index 6d7c594d..9b760144 100644
--- a/core/walk.zig
+++ b/core/walk.zig
@@ -31,8 +31,9 @@
//! .blob = .{ "content" },
//! };
//!
-//! None of the three kinds is in a digest or a dump. A type with a `pub fn
-//! digest(*const T, *Hasher) void` of its own hashes itself; one with
+//! None of the three kinds is in a digest or a dump. A type (a struct or a
+//! tagged union) with a `pub fn digest(*const T, *Hasher) void` of its own
+//! hashes itself; one with
//! `dumpWrite`, `dumpRead` (and `dumpFree`) dumps itself as bytes.
const std = @import("std");
const xitdb = @import("xitdb");
@@ -242,6 +243,7 @@ pub fn hash(comptime T: type, v: *const T, h: *Hasher) void {
},
.@"union" => |u| {
if (u.tag_type == null) @compileError("walk: an untagged union: " ++ @typeName(T));
+ if (comptime @hasDecl(T, "digest") and @TypeOf(T.digest) == fn (*const T, *Hasher) void) return v.digest(h);
const tag: u.tag_type.? = v.*;
hash(u.tag_type.?, &tag, h);
switch (v.*) {