| ... | @@ -325,6 +325,10 @@ pub fn formatType( | ... | @@ -325,6 +325,10 @@ pub fn formatType( |
| 325 | } | 325 | } |
| 326 | | 326 | |
| 327 | const T = @TypeOf(value); | 327 | const T = @TypeOf(value); |
| | 328 | if (comptime std.meta.trait.hasFn("format")(T)) { |
| | 329 | return try value.format(fmt, options, out_stream); |
| | 330 | } |
| | 331 | |
| 328 | switch (@typeInfo(T)) { | 332 | switch (@typeInfo(T)) { |
| 329 | .ComptimeInt, .Int, .Float => { | 333 | .ComptimeInt, .Int, .Float => { |
| 330 | return formatValue(value, fmt, options, out_stream); | 334 | return formatValue(value, fmt, options, out_stream); |
| ... | @@ -354,10 +358,6 @@ pub fn formatType( | ... | @@ -354,10 +358,6 @@ pub fn formatType( |
| 354 | return out_stream.writeAll(@errorName(value)); | 358 | return out_stream.writeAll(@errorName(value)); |
| 355 | }, | 359 | }, |
| 356 | .Enum => |enumInfo| { | 360 | .Enum => |enumInfo| { |
| 357 | if (comptime std.meta.trait.hasFn("format")(T)) { | | |
| 358 | return value.format(fmt, options, out_stream); | | |
| 359 | } | | |
| 360 | | | |
| 361 | try out_stream.writeAll(@typeName(T)); | 361 | try out_stream.writeAll(@typeName(T)); |
| 362 | if (enumInfo.is_exhaustive) { | 362 | if (enumInfo.is_exhaustive) { |
| 363 | try out_stream.writeAll("."); | 363 | try out_stream.writeAll("."); |
| ... | @@ -370,10 +370,6 @@ pub fn formatType( | ... | @@ -370,10 +370,6 @@ pub fn formatType( |
| 370 | } | 370 | } |
| 371 | }, | 371 | }, |
| 372 | .Union => { | 372 | .Union => { |
| 373 | if (comptime std.meta.trait.hasFn("format")(T)) { | | |
| 374 | return value.format(fmt, options, out_stream); | | |
| 375 | } | | |
| 376 | | | |
| 377 | try out_stream.writeAll(@typeName(T)); | 373 | try out_stream.writeAll(@typeName(T)); |
| 378 | if (max_depth == 0) { | 374 | if (max_depth == 0) { |
| 379 | return out_stream.writeAll("{ ... }"); | 375 | return out_stream.writeAll("{ ... }"); |
| ... | @@ -394,10 +390,6 @@ pub fn formatType( | ... | @@ -394,10 +390,6 @@ pub fn formatType( |
| 394 | } | 390 | } |
| 395 | }, | 391 | }, |
| 396 | .Struct => |StructT| { | 392 | .Struct => |StructT| { |
| 397 | if (comptime std.meta.trait.hasFn("format")(T)) { | | |
| 398 | return value.format(fmt, options, out_stream); | | |
| 399 | } | | |
| 400 | | | |
| 401 | try out_stream.writeAll(@typeName(T)); | 393 | try out_stream.writeAll(@typeName(T)); |
| 402 | if (max_depth == 0) { | 394 | if (max_depth == 0) { |
| 403 | return out_stream.writeAll("{ ... }"); | 395 | return out_stream.writeAll("{ ... }"); |