authorgravatar for rganesan@gmail.comGanesan Rajagopal <rganesan@gmail.com> 2022-11-06 11:26:27+05:30
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 13:53:37-07:00
log1be11e230a453700bcf8cd0d75e0dd7c3a30c2f0
tree3c70f336119f132980fa83ef2fd93e2858258793
parent6ea3d3e19fce2317e8d7e60a78307f16f2538d72

langref.html.in: Simplify printing types in examples

zig stdlib fmt has a formatter for types which prints the type name. So, just use @TypeOf(type) instead of the longer @typeInfo(@TypeOf(type)).

1 files changed, 9 insertions(+), 14 deletions(-)

doc/langref.html.in+9-14
......@@ -575,32 +575,27 @@ pub fn main() void {
575575 var optional_value: ?[]const u8 = null;
576576 assert(optional_value == null);
577577
578 print("\noptional 1\ntype: {s}\nvalue: {?s}\n", .{
579 @typeName(@TypeOf(optional_value)),
580 optional_value,
578 print("\noptional 1\ntype: {}\nvalue: {?s}\n", .{
579 @TypeOf(optional_value), optional_value,
581580 });
582581
583582 optional_value = "hi";
584583 assert(optional_value != null);
585584
586 print("\noptional 2\ntype: {s}\nvalue: {?s}\n", .{
587 @typeName(@TypeOf(optional_value)),
588 optional_value,
585 print("\noptional 2\ntype: {}\nvalue: {?s}\n", .{
586 @TypeOf(optional_value), optional_value,
589587 });
590588
591589 // error union
592590 var number_or_error: anyerror!i32 = error.ArgNotFound;
593591
594 print("\nerror union 1\ntype: {s}\nvalue: {!}\n", .{
595 @typeName(@TypeOf(number_or_error)),
596 number_or_error,
597 });
592 print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{
593 @TypeOf(number_or_error), number_or_error, });
598594
599595 number_or_error = 1234;
600596
601 print("\nerror union 2\ntype: {s}\nvalue: {!}\n", .{
602 @typeName(@TypeOf(number_or_error)),
603 number_or_error,
597 print("\nerror union 2\ntype: {}\nvalue: {!}\n", .{
598 @TypeOf(number_or_error), number_or_error,
604599 });
605600}
606601 {#code_end#}
......@@ -859,7 +854,7 @@ const mem = @import("std").mem; // will be used to compare bytes
859854
860855pub fn main() void {
861856 const bytes = "hello";
862 print("{s}\n", .{@typeName(@TypeOf(bytes))}); // *const [5:0]u8
857 print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8
863858 print("{d}\n", .{bytes.len}); // 5
864859 print("{c}\n", .{bytes[1]}); // 'e'
865860 print("{d}\n", .{bytes[5]}); // 0