mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
explicitly specify error set of std.json.stringify
This commit is contained in:
parent
2b8c1f0d46
commit
3bf0b8eada
@ -140,7 +140,7 @@ pub fn stringify(
|
||||
value: anytype,
|
||||
options: StringifyOptions,
|
||||
out_stream: anytype,
|
||||
) !void {
|
||||
) @TypeOf(out_stream).Error!void {
|
||||
const T = @TypeOf(value);
|
||||
switch (@typeInfo(T)) {
|
||||
.Float, .ComptimeFloat => {
|
||||
|
||||
@ -260,23 +260,6 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
|
||||
if (vos.expected_remaining.len > 0) return error.NotEnoughData;
|
||||
}
|
||||
|
||||
test "stringify struct with custom stringify that returns a custom error" {
|
||||
var ret = stringify(struct {
|
||||
field: Field = .{},
|
||||
|
||||
pub const Field = struct {
|
||||
field: ?[]*Field = null,
|
||||
|
||||
const Self = @This();
|
||||
pub fn jsonStringify(_: Self, _: StringifyOptions, _: anytype) error{CustomError}!void {
|
||||
return error.CustomError;
|
||||
}
|
||||
};
|
||||
}{}, StringifyOptions{}, std.io.null_writer);
|
||||
|
||||
try std.testing.expectError(error.CustomError, ret);
|
||||
}
|
||||
|
||||
test "stringify alloc" {
|
||||
const allocator = std.testing.allocator;
|
||||
const expected =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user