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