refactor: use enum type for buffer references
This commit is contained in:
parent
5438f19015
commit
9b02a8f6e9
4 changed files with 51 additions and 35 deletions
|
|
@ -1750,3 +1750,25 @@ pub fn extract_state(self: *Self, iter: *[]const u8) !void {
|
|||
try self.reset_from_string_and_update(content);
|
||||
if (dirty) self.mark_dirty();
|
||||
}
|
||||
|
||||
pub fn to_ref(self: *Self) Ref {
|
||||
return @enumFromInt(@intFromPtr(self));
|
||||
}
|
||||
|
||||
pub const Ref = enum(usize) {
|
||||
_,
|
||||
|
||||
pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void {
|
||||
const value: usize = @intFromEnum(self);
|
||||
try cbor.writeValue(writer, value);
|
||||
}
|
||||
|
||||
pub fn cborExtract(self: *@This(), iter: *[]const u8) cbor.Error!bool {
|
||||
var value: usize = 0;
|
||||
if (try cbor.matchValue(iter, cbor.extract(&value))) {
|
||||
self.* = @enumFromInt(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue