| ... | ... | @@ -575,32 +575,27 @@ pub fn main() void { |
| 575 | 575 | var optional_value: ?[]const u8 = null; |
| 576 | 576 | assert(optional_value == null); |
| 577 | 577 | |
| 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, |
| 581 | 580 | }); |
| 582 | 581 | |
| 583 | 582 | optional_value = "hi"; |
| 584 | 583 | assert(optional_value != null); |
| 585 | 584 | |
| 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, |
| 589 | 587 | }); |
| 590 | 588 | |
| 591 | 589 | // error union |
| 592 | 590 | var number_or_error: anyerror!i32 = error.ArgNotFound; |
| 593 | 591 | |
| 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, }); |
| 598 | 594 | |
| 599 | 595 | number_or_error = 1234; |
| 600 | 596 | |
| 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, |
| 604 | 599 | }); |
| 605 | 600 | } |
| 606 | 601 | {#code_end#} |
| ... | ... | @@ -859,7 +854,7 @@ const mem = @import("std").mem; // will be used to compare bytes |
| 859 | 854 | |
| 860 | 855 | pub fn main() void { |
| 861 | 856 | const bytes = "hello"; |
| 862 | | print("{s}\n", .{@typeName(@TypeOf(bytes))}); // *const [5:0]u8 |
| 857 | print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8 |
| 863 | 858 | print("{d}\n", .{bytes.len}); // 5 |
| 864 | 859 | print("{c}\n", .{bytes[1]}); // 'e' |
| 865 | 860 | print("{d}\n", .{bytes[5]}); // 0 |