]> gitweb.ps.run Git - chirp/blobdiff - src/main.zig
change reencode to include return type as parameter
[chirp] / src / main.zig
index 2f7fd4cd7ebbe699dd1b1a89b982d591e1c83dfb..7fe3b637717730fb35208295b09ce4e031d04625 100644 (file)
@@ -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,