| ... | @@ -122,7 +122,7 @@ pub fn valueMaxDepth(self: *Serializer, val: anytype, options: ValueOptions, dep | ... | @@ -122,7 +122,7 @@ pub fn valueMaxDepth(self: *Serializer, val: anytype, options: ValueOptions, dep |
| 122 | | 122 | |
| 123 | /// Serialize a value, similar to `serializeArbitraryDepth`. | 123 | /// Serialize a value, similar to `serializeArbitraryDepth`. |
| 124 | pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOptions) Error!void { | 124 | pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOptions) Error!void { |
| 125 | comptime assert(canSerializeType(@TypeOf(val))); | 125 | comptime assertCanSerializeType(@TypeOf(val)); |
| 126 | switch (@typeInfo(@TypeOf(val))) { | 126 | switch (@typeInfo(@TypeOf(val))) { |
| 127 | .int, .comptime_int => if (options.emit_codepoint_literals.emitAsCodepoint(val)) |c| { | 127 | .int, .comptime_int => if (options.emit_codepoint_literals.emitAsCodepoint(val)) |c| { |
| 128 | self.codePoint(c) catch |err| switch (err) { | 128 | self.codePoint(c) catch |err| switch (err) { |
| ... | @@ -321,7 +321,7 @@ pub fn tupleArbitraryDepth( | ... | @@ -321,7 +321,7 @@ pub fn tupleArbitraryDepth( |
| 321 | } | 321 | } |
| 322 | | 322 | |
| 323 | fn tupleImpl(self: *Serializer, val: anytype, options: ValueOptions) Error!void { | 323 | fn tupleImpl(self: *Serializer, val: anytype, options: ValueOptions) Error!void { |
| 324 | comptime assert(canSerializeType(@TypeOf(val))); | 324 | comptime assertCanSerializeType(@TypeOf(val)); |
| 325 | switch (@typeInfo(@TypeOf(val))) { | 325 | switch (@typeInfo(@TypeOf(val))) { |
| 326 | .@"struct" => { | 326 | .@"struct" => { |
| 327 | var container = try self.beginTuple(.{ .whitespace_style = .{ .fields = val.len } }); | 327 | var container = try self.beginTuple(.{ .whitespace_style = .{ .fields = val.len } }); |
| ... | @@ -814,6 +814,10 @@ test checkValueDepth { | ... | @@ -814,6 +814,10 @@ test checkValueDepth { |
| 814 | try expectValueDepthEquals(3, @as([]const []const u8, &.{&.{ 1, 2, 3 }})); | 814 | try expectValueDepthEquals(3, @as([]const []const u8, &.{&.{ 1, 2, 3 }})); |
| 815 | } | 815 | } |
| 816 | | 816 | |
| | 817 | inline fn assertCanSerializeType(T: type) void { |
| | 818 | if (!canSerializeType(T)) @compileError("cannot serialize: " ++ @typeName(T)); |
| | 819 | } |
| | 820 | |
| 817 | inline fn canSerializeType(T: type) bool { | 821 | inline fn canSerializeType(T: type) bool { |
| 818 | comptime return canSerializeTypeInner(T, &.{}, false); | 822 | comptime return canSerializeTypeInner(T, &.{}, false); |
| 819 | } | 823 | } |