46 lines
1.1 KiB
Zig
46 lines
1.1 KiB
Zig
const std = @import("std");
|
|
const getty = @import("getty");
|
|
const types = @import("../types.zig");
|
|
|
|
const Vis = struct {
|
|
pub usingnamespace getty.de.Visitor(
|
|
@This(),
|
|
types.LineAndColumn,
|
|
.{ .visitSeq = visitSeq },
|
|
);
|
|
|
|
pub fn visitSeq(
|
|
_: @This(),
|
|
alloc: ?std.mem.Allocator,
|
|
comptime Deserializer: type,
|
|
input: anytype,
|
|
) Deserializer.Error!types.LineAndColumn {
|
|
const line = (try input.nextElement(alloc, isize)) orelse
|
|
return error.InvalidLength;
|
|
const column = (try input.nextElement(alloc, usize)) orelse
|
|
return error.InvalidLength;
|
|
|
|
return types.LineAndColumn{
|
|
.line = line,
|
|
.column = column,
|
|
};
|
|
}
|
|
};
|
|
|
|
pub fn is(comptime T: type) bool {
|
|
return T == types.LineAndColumn;
|
|
}
|
|
|
|
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.deserializeSeq(alloc, visitor);
|
|
}
|