X-Git-Url: https://gitweb.ps.run/chirp/blobdiff_plain/6a5bd646d03ad9796f00b639881c3b3e25ee35f2..13381fcc62fea793dc9c4af62e4b59927b9ae94f:/src/main.zig diff --git a/src/main.zig b/src/main.zig index 2f7fd4c..0800e2b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -97,8 +97,8 @@ fn parse_enum(comptime E: type, buf: []const u8, base: u8) !E { } // https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding -fn reencode(text: []const u8) !PostText { - var result = try PostText.init(0); +fn reencode(comptime T: type, text: []const u8) !T { + var result = try T.init(0); const len = @min(text.len, 1024); // TODO: PostText length @@ -286,7 +286,7 @@ const Chirp = struct { const posts = try Db.posts(txn); post_id = try db.Prng.gen(posts.dbi, PostId); - const decoded_text = try reencode(text); + const decoded_text = try reencode(PostText, text); try posts.put(post_id, Post{ .id = post_id, .parent_id = parent_id, @@ -463,16 +463,12 @@ pub fn Paginate(comptime T: type) type { it.idx = try parse_enum(T.Base.Key, starting_at_str, 16); } - if (it.idx == null) { - return error.InvalidIterator; - } - return .{ .res = res, .view = view, .per_page = per_page, .it = it, - .starting_idx = it.idx.?, + .starting_idx = it.idx, }; } pub fn next(self: *Self) IterateResult {