diff --git a/src/json.zig b/src/json.zig index f522607..6299763 100644 --- a/src/json.zig +++ b/src/json.zig @@ -977,8 +977,8 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er return try parseInto(optionalInfo.child, allocator, value); // optional }, .@"union" => |unionInfo| { - if (std.meta.hasFn(T, "toJson")) { - return try T.toJson(allocator, value); + if (std.meta.hasFn(T, "json")) { + return try T.json(allocator, value); } var result: ?T = null; @@ -1027,8 +1027,8 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er return result.?; }, .@"enum" => { - if (std.meta.hasFn(T, "toJson")) - return try T.toJson(allocator, value); + if (std.meta.hasFn(T, "json")) + return try T.json(allocator, value); switch (value) { .string => return std.meta.stringToEnum(T, value.string).?, // useful for parsing a name into enum T @@ -1038,8 +1038,8 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er }, .@"struct" => |structInfo| { var r: T = undefined; - if (std.meta.hasFn(T, "toJson")) - return try T.toJson(allocator, value); + if (std.meta.hasFn(T, "json")) + return try T.json(allocator, value); if (!value.is(.object)) @panic("tried to cast a non-object into: " ++ @typeName(T)); @@ -1128,8 +1128,8 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er else => return error.TypeMismatch, // may only cast string, array }, else => { - if (std.meta.hasFn(T, "toJson")) - return T.toJson(allocator, value); + if (std.meta.hasFn(T, "json")) + return T.json(allocator, value); return error.TypeMismatch; // unsupported type }, }, @@ -1224,7 +1224,7 @@ pub fn parseRight(comptime L: type, comptime R: type, child_allocator: mem.Alloc pub fn Record(comptime T: type) type { return struct { map: std.StringHashMapUnmanaged(T), - pub fn toJson(allocator: mem.Allocator, value: JsonType) !@This() { + pub fn json(allocator: mem.Allocator, value: JsonType) !@This() { var map: std.StringHashMapUnmanaged(T) = .init; var iterator = value.object.iterator(); @@ -1270,7 +1270,7 @@ pub fn AssociativeArray(comptime E: type, comptime V: type) type { return struct { map: std.EnumMap(E, V), - pub fn toJson(allocator: mem.Allocator, value: JsonType) !@This() { + pub fn json(allocator: mem.Allocator, value: JsonType) !@This() { var map: std.EnumMap(E, V) = .{}; var iterator = value.object.iterator(); diff --git a/src/structures/component.zig b/src/structures/component.zig index e5d527e..50099e0 100644 --- a/src/structures/component.zig +++ b/src/structures/component.zig @@ -153,7 +153,7 @@ pub const SelectMenu = union(MessageComponentTypes) { SelectMenuUsersAndRoles: SelectMenuUsersAndRoles, SelectMenuChannels: SelectMenuChannels, - pub fn toJson(allocator: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(allocator: std.mem.Allocator, value: zjson.JsonType) !@This() { if (!value.is(.object)) @panic("coulnd't match against non-object type"); @@ -211,7 +211,7 @@ pub const MessageComponent = union(MessageComponentTypes) { SelectMenuUsersAndRoles: SelectMenuUsersAndRoles, SelectMenuChannels: SelectMenuChannels, - pub fn toJson(allocator: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(allocator: std.mem.Allocator, value: zjson.JsonType) !@This() { if (!value.is(.object)) @panic("coulnd't match against non-object type"); diff --git a/src/structures/shared.zig b/src/structures/shared.zig index 0de15b9..7f5b6c3 100644 --- a/src/structures/shared.zig +++ b/src/structures/shared.zig @@ -43,7 +43,7 @@ pub const UserFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u34)); } @@ -83,7 +83,7 @@ pub const PremiumUsageFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u8)); } @@ -102,7 +102,7 @@ pub const PurchasedFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u8)); } @@ -122,7 +122,7 @@ pub const MemberFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u16)); } @@ -198,7 +198,7 @@ pub const ChannelFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u32)); } @@ -224,7 +224,7 @@ pub const RoleFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u2)); } @@ -242,7 +242,7 @@ pub const AttachmentFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u8)); } @@ -263,7 +263,7 @@ pub const SkuFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u16)); } @@ -288,7 +288,7 @@ pub const MessageFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u16)); } @@ -328,7 +328,7 @@ pub const ActivityFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u16)); } @@ -366,7 +366,7 @@ pub const ApplicationFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u32)); } @@ -577,7 +577,7 @@ pub const SystemChannelFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u8)); } @@ -622,7 +622,7 @@ pub const ChannelTypes = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u32)); } @@ -949,7 +949,7 @@ pub const BitwisePermissionFlags = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u64)); } @@ -1296,7 +1296,7 @@ pub const GatewayIntents = packed struct { return @bitCast(raw); } - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { return @bitCast(value.number.cast(u32)); } /// diff --git a/src/structures/snowflake.zig b/src/structures/snowflake.zig index a45f486..c5d70c0 100644 --- a/src/structures/snowflake.zig +++ b/src/structures/snowflake.zig @@ -54,7 +54,7 @@ pub const Snowflake = enum(u64) { } /// zjson parse - pub fn toJson(_: std.mem.Allocator, value: zjson.JsonType) !@This() { + pub fn json(_: std.mem.Allocator, value: zjson.JsonType) !@This() { if (value.is(.string)) return Snowflake.fromRaw(value.string) catch std.debug.panic("invalid snowflake: {s}\n", .{value.string});