]> gitweb.ps.run Git - chirp/blobdiff - src/main.zig
update main.zig
[chirp] / src / main.zig
index 164606f245754a94d5998a779833f42b3d715783..29bedcfb4159e6ef7264ce47aed6ef25a02da73a 100644 (file)
@@ -97,7 +97,7 @@ const PostListList = db.List(SavedPostList);
 const UserListList = db.List(SavedUserList);
 
 fn parse_enum(comptime E: type, buf: []const u8, base: u8) !E {
-    return @enumFromInt(try std.fmt.parseUnsigned(@typeInfo(E).Enum.tag_type, buf, base));
+    return @enumFromInt(try std.fmt.parseUnsigned(@typeInfo(E).@"enum".tag_type, buf, base));
 }
 
 // https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
@@ -467,7 +467,7 @@ pub fn Paginate(comptime T: type) type {
                 .starting_idx = it.idx,
             };
         }
-        pub fn next(self: *Self) IterateResult {
+        pub fn next(self: *Self) ?IterateResult {
             if (self.it.next()) |kv| {
                 if (self.count < self.per_page) {
                     self.count += 1;
@@ -509,7 +509,7 @@ fn html_form(res: *http.Response, action: []const u8, inputs: anytype) !void {
 
     inline for (inputs) |input| {
         switch (@typeInfo(@TypeOf(input))) {
-            .Struct => |s| {
+            .@"struct" => |s| {
                 if (s.fields.len == 3) {
                     try res.write("<{s} ", .{input[0]});
                     try res.write(input[1], input[2]);
@@ -969,20 +969,20 @@ const GET = struct {
 
     fn handle(self: Self) !bool {
         const ti = @typeInfo(Self);
-        inline for (ti.Struct.decls) |f_decl| {
+        inline for (ti.@"struct".decls) |f_decl| {
             const has_arg = f_decl.name.len > 1 and f_decl.name[f_decl.name.len - 1] == '/';
             const match = if (has_arg) std.mem.startsWith(u8, self.req.target, f_decl.name) else std.mem.eql(u8, self.req.target, f_decl.name);
 
             if (match) {
                 const f = @field(Self, f_decl.name);
                 const fi = @typeInfo(@TypeOf(f));
-                if (fi.Fn.params.len == 1) {
+                if (fi.@"fn".params.len == 1) {
                     try @call(.auto, f, .{self});
                 } else {
-                    const arg_type = fi.Fn.params[1].type.?;
+                    const arg_type = fi.@"fn".params[1].type.?;
                     const arg_info = @typeInfo(arg_type);
                     var arg: arg_type = undefined;
-                    const field = arg_info.Struct.fields[0];
+                    const field = arg_info.@"struct".fields[0];
                     if (self.req.target.len <= f_decl.name.len) {
                         return error.NoArgProvided;
                     }
@@ -990,10 +990,10 @@ const GET = struct {
                     const field_ti = @typeInfo(field.type);
                     switch (field_ti) {
                         // TODO: maybe handle BoundedArray?
-                        .Int => {
+                        .int => {
                             @field(arg, field.name) = try std.fmt.parseUnsigned(field.type, str, 16);
                         },
-                        .Enum => {
+                        .@"enum" => {
                             @field(arg, field.name) = try parse_enum(field.type, str, 16);
                         },
                         else => {
@@ -1305,24 +1305,24 @@ const POST = struct {
 
     pub fn handle(self: Self) !bool {
         const ti = @typeInfo(Self);
-        inline for (ti.Struct.decls) |f_decl| {
+        inline for (ti.@"struct".decls) |f_decl| {
             if (std.mem.eql(u8, f_decl.name, self.req.target)) {
                 const f = @field(Self, f_decl.name);
                 const fi = @typeInfo(@TypeOf(f));
-                if (fi.Fn.params.len == 1) {
+                if (fi.@"fn".params.len == 1) {
                     _ = try @call(.auto, f, .{self});
                 } else {
-                    const args_type = fi.Fn.params[fi.Fn.params.len - 1].type.?;
+                    const args_type = fi.@"fn".params[fi.@"fn".params.len - 1].type.?;
                     const argsi = @typeInfo(args_type);
                     var args: args_type = undefined;
-                    inline for (argsi.Struct.fields) |field| {
+                    inline for (argsi.@"struct".fields) |field| {
                         const str = self.req.get_value(field.name) orelse return error.ArgNotFound;
                         const field_ti = @typeInfo(field.type);
                         switch (field_ti) {
-                            .Int => {
+                            .int => {
                                 @field(args, field.name) = try std.fmt.parseUnsigned(field.type, str, 16);
                             },
-                            .Enum => {
+                            .@"enum" => {
                                 @field(args, field.name) = try parse_enum(field.type, str, 16);
                             },
                             else => {