41 lines
885 B
Zig
41 lines
885 B
Zig
const std = @import("std");
|
|
const getty = @import("getty");
|
|
const types = @import("../types.zig");
|
|
|
|
const Vis = struct {
|
|
pub usingnamespace getty.de.Visitor(
|
|
@This(),
|
|
types.Char,
|
|
.{ .visitString = visitString },
|
|
);
|
|
|
|
pub fn visitString(
|
|
_: @This(),
|
|
_: ?std.mem.Allocator,
|
|
comptime Deserializer: type,
|
|
input: anytype,
|
|
) Deserializer.Error!types.Char {
|
|
if (input.len != 1)
|
|
return error.InvalidLength;
|
|
|
|
return types.Char{ .c = input[0] };
|
|
}
|
|
};
|
|
|
|
pub fn is(comptime T: type) bool {
|
|
return T == types.Char;
|
|
}
|
|
|
|
pub fn Visitor(comptime _: type) type {
|
|
return Vis;
|
|
}
|
|
|
|
pub fn deserialize(
|
|
alloc: ?std.mem.Allocator,
|
|
comptime _: type,
|
|
deserializer: anytype,
|
|
visitor: anytype,
|
|
) !@TypeOf(visitor).Value {
|
|
return try deserializer.deserializeString(alloc, visitor);
|
|
}
|