lib/choir/src/backends/artifact/model/verification.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const Allocator = std.mem.Allocator;
3 const artifact = @import("root.zig");
4 const slice = artifact.slice;
5
6 pub const VerificationState = enum(u8) {
7 not_run = 1,
8 passed = 2,
9 failed = 3,
10 skipped = 4,
11 };
12
13 pub const VerificationStatus = struct {
14 state: VerificationState = .not_run,
15 stage: ?[]const u8 = null,
16 message: ?[]const u8 = null,
17
18 pub fn dupe(self: VerificationStatus, allocator: Allocator) Allocator.Error!VerificationStatus {
19 var out = VerificationStatus{ .state = self.state };
20 errdefer out.deinit(allocator);
21 out.stage = try slice.dupeOptional(allocator, self.stage);
22 out.message = try slice.dupeOptional(allocator, self.message);
23 return out;
24 }
25
26 pub fn deinit(self: *VerificationStatus, allocator: Allocator) void {
27 slice.freeOptional(allocator, self.stage);
28 slice.freeOptional(allocator, self.message);
29 self.* = .{};
30 }
31
32 pub fn eql(self: VerificationStatus, other: VerificationStatus) bool {
33 return self.state == other.state and
34 slice.optionalEqual(self.stage, other.stage) and
35 slice.optionalEqual(self.message, other.message);
36 }
37
38 pub fn replace(self: *VerificationStatus, allocator: Allocator, status: VerificationStatus) Allocator.Error!void {
39 const owned = try status.dupe(allocator);
40 self.deinit(allocator);
41 self.* = owned;
42 }
43 };