diff --git a/examples/endpoint/users.zig b/examples/endpoint/users.zig index 7e0a825..8e2d500 100644 --- a/examples/endpoint/users.zig +++ b/examples/endpoint/users.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const zap = @import("zap"); alloc: std.mem.Allocator = undefined, users: std.AutoHashMap(usize, InternalUser) = undefined, @@ -129,7 +128,7 @@ pub fn toJSON(self: *Self) ![]const u8 { } std.debug.assert(self.users.count() == l.items.len); std.debug.assert(self.count == l.items.len); - return zap.stringifyArrayListAlloc(self.alloc, User, &l, .{}); + return std.json.stringifyAlloc(self.alloc, l.items, .{}); } // diff --git a/src/util.zig b/src/util.zig index 6f1702c..bc739fb 100644 --- a/src/util.zig +++ b/src/util.zig @@ -60,44 +60,3 @@ pub fn stringifyBuf( return null; } } - -/// provide your own buf, NOT mutex-protected -pub fn stringifyArrayListBuf( - buffer: []u8, - comptime T: anytype, - list: *std.ArrayList(T), - options: std.json.StringifyOptions, -) !?[]const u8 { - var fba = std.heap.FixedBufferAllocator.init(buffer); - var string = std.ArrayList(u8).init(fba.allocator()); - var writer = string.writer(); - try writer.writeByte('['); - var first: bool = true; - for (list.items) |user| { - if (!first) try writer.writeByte(','); - first = false; - try std.json.stringify(user, options, string.writer()); - } - try writer.writeByte(']'); - return string.items; -} - -/// provide your own allocator, NOT mutex-protected -pub fn stringifyArrayListAlloc( - a: std.mem.Allocator, - comptime T: anytype, - list: *std.ArrayList(T), - options: std.json.StringifyOptions, -) ![]const u8 { - var string = std.ArrayList(u8).init(a); - var writer = string.writer(); - try writer.writeByte('['); - var first: bool = true; - for (list.items) |item| { - if (!first) try writer.writeByte(','); - first = false; - try std.json.stringify(item, options, string.writer()); - } - try writer.writeByte(']'); - return string.toOwnedSlice(); -}