Skip to content

Commit

Permalink
Merge pull request #158 from ion232/fix-examples-for-zig-0.13.0
Browse files Browse the repository at this point in the history
Fix examples for zig 0.13.0
  • Loading branch information
ibokuri authored Dec 31, 2024
2 parents 78738b6 + 426e87c commit a78731b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions examples/bool-deserializer/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn Deserializer(comptime Reader: type) type {
self.tokens.deinit();
}

fn deserializeBool(self: *Self, ally: ?std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
fn deserializeBool(self: *Self, ally: std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
const token = try self.tokens.next();
if (token == .true or token == .false) {
return try v.visitBool(ally, De, token == .true);
Expand All @@ -47,13 +47,15 @@ fn Deserializer(comptime Reader: type) type {
}

pub fn main() anyerror!void {
const page_ally = std.heap.page_allocator;

var fbs = std.io.fixedBufferStream("true");
const reader = fbs.reader();

var d = Deserializer(@TypeOf(reader)).init(std.heap.page_allocator, reader);
var d = Deserializer(@TypeOf(reader)).init(page_ally, reader);
defer d.deinit();

const v = try getty.deserialize(null, bool, d.deserializer());
const v = try getty.deserialize(page_ally, bool, d.deserializer());

std.debug.print("{}, {}\n", .{ v, @TypeOf(v) });
}
2 changes: 1 addition & 1 deletion examples/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void {

const exe = b.addExecutable(.{
.name = exe_name,
.root_source_file = .{ .path = example_path },
.root_source_file = b.path(example_path),
.target = target,
.optimize = optimize,
});
Expand Down
8 changes: 4 additions & 4 deletions examples/seq-deserializer/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn Deserializer(comptime Reader: type) type {
self.tokens.deinit();
}

fn deserializeBool(self: *Self, ally: ?std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
fn deserializeBool(self: *Self, ally: std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
const token = try self.tokens.next();
if (token == .true or token == .false) {
return try v.visitBool(ally, De, token == .true);
Expand All @@ -45,7 +45,7 @@ fn Deserializer(comptime Reader: type) type {
return error.InvalidType;
}

fn deserializeSeq(self: *Self, ally: ?std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
fn deserializeSeq(self: *Self, ally: std.mem.Allocator, v: anytype) Error!@TypeOf(v).Value {
const token = try self.tokens.next();
if (token == .array_begin) {
var sa = SeqAccess{ .de = self };
Expand All @@ -66,7 +66,7 @@ fn Deserializer(comptime Reader: type) type {
},
);

fn nextElementSeed(self: *@This(), ally: ?std.mem.Allocator, seed: anytype) Error!?@TypeOf(seed).Value {
fn nextElementSeed(self: *@This(), ally: std.mem.Allocator, seed: anytype) Error!?@TypeOf(seed).Value {
// If ']' is encountered, return null
if (try self.de.tokens.peekNextTokenType() == .array_end) {
return null;
Expand All @@ -92,5 +92,5 @@ pub fn main() anyerror!void {
const v = try getty.deserialize(page_ally, std.ArrayList(bool), d.deserializer());
defer v.deinit();

std.debug.print("{any}, {}\n", .{ v.items, @TypeOf(v) });
std.debug.print("{any}, {}\n", .{ v.value, @TypeOf(v) });
}
2 changes: 1 addition & 1 deletion examples/seq-serializer/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ pub fn main() anyerror!void {
try getty.serialize(null, list, s);

// std.BoundedArray
var arr = try std.BoundedArray(bool, 2).fromSlice(&.{ true, false });
const arr = try std.BoundedArray(bool, 2).fromSlice(&.{ true, false });
try getty.serialize(null, arr, s);
}

0 comments on commit a78731b

Please sign in to comment.