| ... | ... | @@ -205,7 +205,7 @@ const std = @import("std"); |
| 205 | 205 | |
| 206 | 206 | pub fn main() !void { |
| 207 | 207 | const stdout = &std.io.getStdOut().outStream().stream; |
| 208 | | try stdout.print("Hello, {}!\n", "world"); |
| 208 | try stdout.print("Hello, {}!\n", .{"world"}); |
| 209 | 209 | } |
| 210 | 210 | {#code_end#} |
| 211 | 211 | <p> |
| ... | ... | @@ -217,7 +217,7 @@ pub fn main() !void { |
| 217 | 217 | const warn = @import("std").debug.warn; |
| 218 | 218 | |
| 219 | 219 | pub fn main() void { |
| 220 | | warn("Hello, world!\n"); |
| 220 | warn("Hello, world!\n", .{}); |
| 221 | 221 | } |
| 222 | 222 | {#code_end#} |
| 223 | 223 | <p> |
| ... | ... | @@ -289,41 +289,50 @@ const assert = std.debug.assert; |
| 289 | 289 | pub fn main() void { |
| 290 | 290 | // integers |
| 291 | 291 | const one_plus_one: i32 = 1 + 1; |
| 292 | | warn("1 + 1 = {}\n", one_plus_one); |
| 292 | warn("1 + 1 = {}\n", .{one_plus_one}); |
| 293 | 293 | |
| 294 | 294 | // floats |
| 295 | 295 | const seven_div_three: f32 = 7.0 / 3.0; |
| 296 | | warn("7.0 / 3.0 = {}\n", seven_div_three); |
| 296 | warn("7.0 / 3.0 = {}\n", .{seven_div_three}); |
| 297 | 297 | |
| 298 | 298 | // boolean |
| 299 | | warn("{}\n{}\n{}\n", |
| 299 | warn("{}\n{}\n{}\n", .{ |
| 300 | 300 | true and false, |
| 301 | 301 | true or false, |
| 302 | | !true); |
| 302 | !true, |
| 303 | }); |
| 303 | 304 | |
| 304 | 305 | // optional |
| 305 | 306 | var optional_value: ?[]const u8 = null; |
| 306 | 307 | assert(optional_value == null); |
| 307 | 308 | |
| 308 | | warn("\noptional 1\ntype: {}\nvalue: {}\n", |
| 309 | | @typeName(@typeOf(optional_value)), optional_value); |
| 309 | warn("\noptional 1\ntype: {}\nvalue: {}\n", .{ |
| 310 | @typeName(@typeOf(optional_value)), |
| 311 | optional_value, |
| 312 | }); |
| 310 | 313 | |
| 311 | 314 | optional_value = "hi"; |
| 312 | 315 | assert(optional_value != null); |
| 313 | 316 | |
| 314 | | warn("\noptional 2\ntype: {}\nvalue: {}\n", |
| 315 | | @typeName(@typeOf(optional_value)), optional_value); |
| 317 | warn("\noptional 2\ntype: {}\nvalue: {}\n", .{ |
| 318 | @typeName(@typeOf(optional_value)), |
| 319 | optional_value, |
| 320 | }); |
| 316 | 321 | |
| 317 | 322 | // error union |
| 318 | 323 | var number_or_error: anyerror!i32 = error.ArgNotFound; |
| 319 | 324 | |
| 320 | | warn("\nerror union 1\ntype: {}\nvalue: {}\n", |
| 321 | | @typeName(@typeOf(number_or_error)), number_or_error); |
| 325 | warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{ |
| 326 | @typeName(@typeOf(number_or_error)), |
| 327 | number_or_error, |
| 328 | }); |
| 322 | 329 | |
| 323 | 330 | number_or_error = 1234; |
| 324 | 331 | |
| 325 | | warn("\nerror union 2\ntype: {}\nvalue: {}\n", |
| 326 | | @typeName(@typeOf(number_or_error)), number_or_error); |
| 332 | warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{ |
| 333 | @typeName(@typeOf(number_or_error)), |
| 334 | number_or_error, |
| 335 | }); |
| 327 | 336 | } |
| 328 | 337 | {#code_end#} |
| 329 | 338 | {#header_open|Primitive Types#} |
| ... | ... | @@ -954,8 +963,8 @@ extern fn foo_optimized(x: f64) f64; |
| 954 | 963 | |
| 955 | 964 | pub fn main() void { |
| 956 | 965 | const x = 0.001; |
| 957 | | warn("optimized = {}\n", foo_optimized(x)); |
| 958 | | warn("strict = {}\n", foo_strict(x)); |
| 966 | warn("optimized = {}\n", .{foo_optimized(x)}); |
| 967 | warn("strict = {}\n", .{foo_strict(x)}); |
| 959 | 968 | } |
| 960 | 969 | {#code_end#} |
| 961 | 970 | {#see_also|@setFloatMode|Division by Zero#} |
| ... | ... | @@ -2182,7 +2191,7 @@ test "using slices for strings" { |
| 2182 | 2191 | // You can use slice syntax on an array to convert an array into a slice. |
| 2183 | 2192 | const all_together_slice = all_together[0..]; |
| 2184 | 2193 | // String concatenation example. |
| 2185 | | const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", hello, world); |
| 2194 | const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", .{hello, world}); |
| 2186 | 2195 | |
| 2187 | 2196 | // Generally, you can use UTF-8 and not worry about whether something is a |
| 2188 | 2197 | // string. If you don't need to deal with individual characters, no need |
| ... | ... | @@ -2623,9 +2632,9 @@ const std = @import("std"); |
| 2623 | 2632 | |
| 2624 | 2633 | pub fn main() void { |
| 2625 | 2634 | const Foo = struct {}; |
| 2626 | | std.debug.warn("variable: {}\n", @typeName(Foo)); |
| 2627 | | std.debug.warn("anonymous: {}\n", @typeName(struct {})); |
| 2628 | | std.debug.warn("function: {}\n", @typeName(List(i32))); |
| 2635 | std.debug.warn("variable: {}\n", .{@typeName(Foo)}); |
| 2636 | std.debug.warn("anonymous: {}\n", .{@typeName(struct {})}); |
| 2637 | std.debug.warn("function: {}\n", .{@typeName(List(i32))}); |
| 2629 | 2638 | } |
| 2630 | 2639 | |
| 2631 | 2640 | fn List(comptime T: type) type { |
| ... | ... | @@ -3806,18 +3815,18 @@ test "defer basics" { |
| 3806 | 3815 | // If multiple defer statements are specified, they will be executed in |
| 3807 | 3816 | // the reverse order they were run. |
| 3808 | 3817 | fn deferUnwindExample() void { |
| 3809 | | warn("\n"); |
| 3818 | warn("\n", .{}); |
| 3810 | 3819 | |
| 3811 | 3820 | defer { |
| 3812 | | warn("1 "); |
| 3821 | warn("1 ", .{}); |
| 3813 | 3822 | } |
| 3814 | 3823 | defer { |
| 3815 | | warn("2 "); |
| 3824 | warn("2 ", .{}); |
| 3816 | 3825 | } |
| 3817 | 3826 | if (false) { |
| 3818 | 3827 | // defers are not run if they are never executed. |
| 3819 | 3828 | defer { |
| 3820 | | warn("3 "); |
| 3829 | warn("3 ", .{}); |
| 3821 | 3830 | } |
| 3822 | 3831 | } |
| 3823 | 3832 | } |
| ... | ... | @@ -3832,15 +3841,15 @@ test "defer unwinding" { |
| 3832 | 3841 | // This is especially useful in allowing a function to clean up properly |
| 3833 | 3842 | // on error, and replaces goto error handling tactics as seen in c. |
| 3834 | 3843 | fn deferErrorExample(is_error: bool) !void { |
| 3835 | | warn("\nstart of function\n"); |
| 3844 | warn("\nstart of function\n", .{}); |
| 3836 | 3845 | |
| 3837 | 3846 | // This will always be executed on exit |
| 3838 | 3847 | defer { |
| 3839 | | warn("end of function\n"); |
| 3848 | warn("end of function\n", .{}); |
| 3840 | 3849 | } |
| 3841 | 3850 | |
| 3842 | 3851 | errdefer { |
| 3843 | | warn("encountered an error!\n"); |
| 3852 | warn("encountered an error!\n", .{}); |
| 3844 | 3853 | } |
| 3845 | 3854 | |
| 3846 | 3855 | if (is_error) { |
| ... | ... | @@ -5843,7 +5852,7 @@ const a_number: i32 = 1234; |
| 5843 | 5852 | const a_string = "foobar"; |
| 5844 | 5853 | |
| 5845 | 5854 | pub fn main() void { |
| 5846 | | warn("here is a string: '{}' here is a number: {}\n", a_string, a_number); |
| 5855 | warn("here is a string: '{}' here is a number: {}\n", .{a_string, a_number}); |
| 5847 | 5856 | } |
| 5848 | 5857 | {#code_end#} |
| 5849 | 5858 | |
| ... | ... | @@ -5960,8 +5969,11 @@ const a_number: i32 = 1234; |
| 5960 | 5969 | const a_string = "foobar"; |
| 5961 | 5970 | |
| 5962 | 5971 | test "printf too many arguments" { |
| 5963 | | warn("here is a string: '{}' here is a number: {}\n", |
| 5964 | | a_string, a_number, a_number); |
| 5972 | warn("here is a string: '{}' here is a number: {}\n", .{ |
| 5973 | a_string, |
| 5974 | a_number, |
| 5975 | a_number, |
| 5976 | }); |
| 5965 | 5977 | } |
| 5966 | 5978 | {#code_end#} |
| 5967 | 5979 | <p> |
| ... | ... | @@ -5979,7 +5991,7 @@ const a_string = "foobar"; |
| 5979 | 5991 | const fmt = "here is a string: '{}' here is a number: {}\n"; |
| 5980 | 5992 | |
| 5981 | 5993 | pub fn main() void { |
| 5982 | | warn(fmt, a_string, a_number); |
| 5994 | warn(fmt, .{a_string, a_number}); |
| 5983 | 5995 | } |
| 5984 | 5996 | {#code_end#} |
| 5985 | 5997 | <p> |
| ... | ... | @@ -6417,7 +6429,7 @@ pub fn main() void { |
| 6417 | 6429 | |
| 6418 | 6430 | fn amainWrap() void { |
| 6419 | 6431 | amain() catch |e| { |
| 6420 | | std.debug.warn("{}\n", e); |
| 6432 | std.debug.warn("{}\n", .{e}); |
| 6421 | 6433 | if (@errorReturnTrace()) |trace| { |
| 6422 | 6434 | std.debug.dumpStackTrace(trace.*); |
| 6423 | 6435 | } |
| ... | ... | @@ -6447,8 +6459,8 @@ fn amain() !void { |
| 6447 | 6459 | const download_text = try await download_frame; |
| 6448 | 6460 | defer allocator.free(download_text); |
| 6449 | 6461 | |
| 6450 | | std.debug.warn("download_text: {}\n", download_text); |
| 6451 | | std.debug.warn("file_text: {}\n", file_text); |
| 6462 | std.debug.warn("download_text: {}\n", .{download_text}); |
| 6463 | std.debug.warn("file_text: {}\n", .{file_text}); |
| 6452 | 6464 | } |
| 6453 | 6465 | |
| 6454 | 6466 | var global_download_frame: anyframe = undefined; |
| ... | ... | @@ -6458,7 +6470,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6458 | 6470 | suspend { |
| 6459 | 6471 | global_download_frame = @frame(); |
| 6460 | 6472 | } |
| 6461 | | std.debug.warn("fetchUrl returning\n"); |
| 6473 | std.debug.warn("fetchUrl returning\n", .{}); |
| 6462 | 6474 | return result; |
| 6463 | 6475 | } |
| 6464 | 6476 | |
| ... | ... | @@ -6469,7 +6481,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6469 | 6481 | suspend { |
| 6470 | 6482 | global_file_frame = @frame(); |
| 6471 | 6483 | } |
| 6472 | | std.debug.warn("readFile returning\n"); |
| 6484 | std.debug.warn("readFile returning\n", .{}); |
| 6473 | 6485 | return result; |
| 6474 | 6486 | } |
| 6475 | 6487 | {#code_end#} |
| ... | ... | @@ -6487,7 +6499,7 @@ pub fn main() void { |
| 6487 | 6499 | |
| 6488 | 6500 | fn amainWrap() void { |
| 6489 | 6501 | amain() catch |e| { |
| 6490 | | std.debug.warn("{}\n", e); |
| 6502 | std.debug.warn("{}\n", .{e}); |
| 6491 | 6503 | if (@errorReturnTrace()) |trace| { |
| 6492 | 6504 | std.debug.dumpStackTrace(trace.*); |
| 6493 | 6505 | } |
| ... | ... | @@ -6517,21 +6529,21 @@ fn amain() !void { |
| 6517 | 6529 | const download_text = try await download_frame; |
| 6518 | 6530 | defer allocator.free(download_text); |
| 6519 | 6531 | |
| 6520 | | std.debug.warn("download_text: {}\n", download_text); |
| 6521 | | std.debug.warn("file_text: {}\n", file_text); |
| 6532 | std.debug.warn("download_text: {}\n", .{download_text}); |
| 6533 | std.debug.warn("file_text: {}\n", .{file_text}); |
| 6522 | 6534 | } |
| 6523 | 6535 | |
| 6524 | 6536 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6525 | 6537 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); |
| 6526 | 6538 | errdefer allocator.free(result); |
| 6527 | | std.debug.warn("fetchUrl returning\n"); |
| 6539 | std.debug.warn("fetchUrl returning\n", .{}); |
| 6528 | 6540 | return result; |
| 6529 | 6541 | } |
| 6530 | 6542 | |
| 6531 | 6543 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6532 | 6544 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); |
| 6533 | 6545 | errdefer allocator.free(result); |
| 6534 | | std.debug.warn("readFile returning\n"); |
| 6546 | std.debug.warn("readFile returning\n", .{}); |
| 6535 | 6547 | return result; |
| 6536 | 6548 | } |
| 6537 | 6549 | {#code_end#} |
| ... | ... | @@ -7103,7 +7115,7 @@ const num1 = blk: { |
| 7103 | 7115 | test "main" { |
| 7104 | 7116 | @compileLog("comptime in main"); |
| 7105 | 7117 | |
| 7106 | | warn("Runtime in main, num1 = {}.\n", num1); |
| 7118 | warn("Runtime in main, num1 = {}.\n", .{num1}); |
| 7107 | 7119 | } |
| 7108 | 7120 | {#code_end#} |
| 7109 | 7121 | <p> |
| ... | ... | @@ -7124,7 +7136,7 @@ const num1 = blk: { |
| 7124 | 7136 | }; |
| 7125 | 7137 | |
| 7126 | 7138 | test "main" { |
| 7127 | | warn("Runtime in main, num1 = {}.\n", num1); |
| 7139 | warn("Runtime in main, num1 = {}.\n", .{num1}); |
| 7128 | 7140 | } |
| 7129 | 7141 | {#code_end#} |
| 7130 | 7142 | {#header_close#} |
| ... | ... | @@ -8706,7 +8718,7 @@ const std = @import("std"); |
| 8706 | 8718 | pub fn main() void { |
| 8707 | 8719 | var value: i32 = -1; |
| 8708 | 8720 | var unsigned = @intCast(u32, value); |
| 8709 | | std.debug.warn("value: {}\n", unsigned); |
| 8721 | std.debug.warn("value: {}\n", .{unsigned}); |
| 8710 | 8722 | } |
| 8711 | 8723 | {#code_end#} |
| 8712 | 8724 | <p> |
| ... | ... | @@ -8728,7 +8740,7 @@ const std = @import("std"); |
| 8728 | 8740 | pub fn main() void { |
| 8729 | 8741 | var spartan_count: u16 = 300; |
| 8730 | 8742 | const byte = @intCast(u8, spartan_count); |
| 8731 | | std.debug.warn("value: {}\n", byte); |
| 8743 | std.debug.warn("value: {}\n", .{byte}); |
| 8732 | 8744 | } |
| 8733 | 8745 | {#code_end#} |
| 8734 | 8746 | <p> |
| ... | ... | @@ -8762,7 +8774,7 @@ const std = @import("std"); |
| 8762 | 8774 | pub fn main() void { |
| 8763 | 8775 | var byte: u8 = 255; |
| 8764 | 8776 | byte += 1; |
| 8765 | | std.debug.warn("value: {}\n", byte); |
| 8777 | std.debug.warn("value: {}\n", .{byte}); |
| 8766 | 8778 | } |
| 8767 | 8779 | {#code_end#} |
| 8768 | 8780 | {#header_close#} |
| ... | ... | @@ -8785,11 +8797,11 @@ pub fn main() !void { |
| 8785 | 8797 | var byte: u8 = 255; |
| 8786 | 8798 | |
| 8787 | 8799 | byte = if (math.add(u8, byte, 1)) |result| result else |err| { |
| 8788 | | warn("unable to add one: {}\n", @errorName(err)); |
| 8800 | warn("unable to add one: {}\n", .{@errorName(err)}); |
| 8789 | 8801 | return err; |
| 8790 | 8802 | }; |
| 8791 | 8803 | |
| 8792 | | warn("result: {}\n", byte); |
| 8804 | warn("result: {}\n", .{byte}); |
| 8793 | 8805 | } |
| 8794 | 8806 | {#code_end#} |
| 8795 | 8807 | {#header_close#} |
| ... | ... | @@ -8814,9 +8826,9 @@ pub fn main() void { |
| 8814 | 8826 | |
| 8815 | 8827 | var result: u8 = undefined; |
| 8816 | 8828 | if (@addWithOverflow(u8, byte, 10, &result)) { |
| 8817 | | warn("overflowed result: {}\n", result); |
| 8829 | warn("overflowed result: {}\n", .{result}); |
| 8818 | 8830 | } else { |
| 8819 | | warn("result: {}\n", result); |
| 8831 | warn("result: {}\n", .{result}); |
| 8820 | 8832 | } |
| 8821 | 8833 | } |
| 8822 | 8834 | {#code_end#} |
| ... | ... | @@ -8861,7 +8873,7 @@ const std = @import("std"); |
| 8861 | 8873 | pub fn main() void { |
| 8862 | 8874 | var x: u8 = 0b01010101; |
| 8863 | 8875 | var y = @shlExact(x, 2); |
| 8864 | | std.debug.warn("value: {}\n", y); |
| 8876 | std.debug.warn("value: {}\n", .{y}); |
| 8865 | 8877 | } |
| 8866 | 8878 | {#code_end#} |
| 8867 | 8879 | {#header_close#} |
| ... | ... | @@ -8879,7 +8891,7 @@ const std = @import("std"); |
| 8879 | 8891 | pub fn main() void { |
| 8880 | 8892 | var x: u8 = 0b10101010; |
| 8881 | 8893 | var y = @shrExact(x, 2); |
| 8882 | | std.debug.warn("value: {}\n", y); |
| 8894 | std.debug.warn("value: {}\n", .{y}); |
| 8883 | 8895 | } |
| 8884 | 8896 | {#code_end#} |
| 8885 | 8897 | {#header_close#} |
| ... | ... | @@ -8900,7 +8912,7 @@ pub fn main() void { |
| 8900 | 8912 | var a: u32 = 1; |
| 8901 | 8913 | var b: u32 = 0; |
| 8902 | 8914 | var c = a / b; |
| 8903 | | std.debug.warn("value: {}\n", c); |
| 8915 | std.debug.warn("value: {}\n", .{c}); |
| 8904 | 8916 | } |
| 8905 | 8917 | {#code_end#} |
| 8906 | 8918 | {#header_close#} |
| ... | ... | @@ -8921,7 +8933,7 @@ pub fn main() void { |
| 8921 | 8933 | var a: u32 = 10; |
| 8922 | 8934 | var b: u32 = 0; |
| 8923 | 8935 | var c = a % b; |
| 8924 | | std.debug.warn("value: {}\n", c); |
| 8936 | std.debug.warn("value: {}\n", .{c}); |
| 8925 | 8937 | } |
| 8926 | 8938 | {#code_end#} |
| 8927 | 8939 | {#header_close#} |
| ... | ... | @@ -8942,7 +8954,7 @@ pub fn main() void { |
| 8942 | 8954 | var a: u32 = 10; |
| 8943 | 8955 | var b: u32 = 3; |
| 8944 | 8956 | var c = @divExact(a, b); |
| 8945 | | std.debug.warn("value: {}\n", c); |
| 8957 | std.debug.warn("value: {}\n", .{c}); |
| 8946 | 8958 | } |
| 8947 | 8959 | {#code_end#} |
| 8948 | 8960 | {#header_close#} |
| ... | ... | @@ -8961,7 +8973,7 @@ const std = @import("std"); |
| 8961 | 8973 | pub fn main() void { |
| 8962 | 8974 | var bytes = [5]u8{ 1, 2, 3, 4, 5 }; |
| 8963 | 8975 | var slice = @bytesToSlice(u32, bytes[0..]); |
| 8964 | | std.debug.warn("value: {}\n", slice[0]); |
| 8976 | std.debug.warn("value: {}\n", .{slice[0]}); |
| 8965 | 8977 | } |
| 8966 | 8978 | {#code_end#} |
| 8967 | 8979 | {#header_close#} |
| ... | ... | @@ -8980,7 +8992,7 @@ const std = @import("std"); |
| 8980 | 8992 | pub fn main() void { |
| 8981 | 8993 | var optional_number: ?i32 = null; |
| 8982 | 8994 | var number = optional_number.?; |
| 8983 | | std.debug.warn("value: {}\n", number); |
| 8995 | std.debug.warn("value: {}\n", .{number}); |
| 8984 | 8996 | } |
| 8985 | 8997 | {#code_end#} |
| 8986 | 8998 | <p>One way to avoid this crash is to test for null instead of assuming non-null, with |
| ... | ... | @@ -8991,9 +9003,9 @@ pub fn main() void { |
| 8991 | 9003 | const optional_number: ?i32 = null; |
| 8992 | 9004 | |
| 8993 | 9005 | if (optional_number) |number| { |
| 8994 | | warn("got number: {}\n", number); |
| 9006 | warn("got number: {}\n", .{number}); |
| 8995 | 9007 | } else { |
| 8996 | | warn("it's null\n"); |
| 9008 | warn("it's null\n", .{}); |
| 8997 | 9009 | } |
| 8998 | 9010 | } |
| 8999 | 9011 | {#code_end#} |
| ... | ... | @@ -9016,7 +9028,7 @@ const std = @import("std"); |
| 9016 | 9028 | |
| 9017 | 9029 | pub fn main() void { |
| 9018 | 9030 | const number = getNumberOrFail() catch unreachable; |
| 9019 | | std.debug.warn("value: {}\n", number); |
| 9031 | std.debug.warn("value: {}\n", .{number}); |
| 9020 | 9032 | } |
| 9021 | 9033 | |
| 9022 | 9034 | fn getNumberOrFail() !i32 { |
| ... | ... | @@ -9032,9 +9044,9 @@ pub fn main() void { |
| 9032 | 9044 | const result = getNumberOrFail(); |
| 9033 | 9045 | |
| 9034 | 9046 | if (result) |number| { |
| 9035 | | warn("got number: {}\n", number); |
| 9047 | warn("got number: {}\n", .{number}); |
| 9036 | 9048 | } else |err| { |
| 9037 | | warn("got error: {}\n", @errorName(err)); |
| 9049 | warn("got error: {}\n", .{@errorName(err)}); |
| 9038 | 9050 | } |
| 9039 | 9051 | } |
| 9040 | 9052 | |
| ... | ... | @@ -9061,7 +9073,7 @@ pub fn main() void { |
| 9061 | 9073 | var err = error.AnError; |
| 9062 | 9074 | var number = @errorToInt(err) + 500; |
| 9063 | 9075 | var invalid_err = @intToError(number); |
| 9064 | | std.debug.warn("value: {}\n", number); |
| 9076 | std.debug.warn("value: {}\n", .{number}); |
| 9065 | 9077 | } |
| 9066 | 9078 | {#code_end#} |
| 9067 | 9079 | {#header_close#} |
| ... | ... | @@ -9091,7 +9103,7 @@ const Foo = enum { |
| 9091 | 9103 | pub fn main() void { |
| 9092 | 9104 | var a: u2 = 3; |
| 9093 | 9105 | var b = @intToEnum(Foo, a); |
| 9094 | | std.debug.warn("value: {}\n", @tagName(b)); |
| 9106 | std.debug.warn("value: {}\n", .{@tagName(b)}); |
| 9095 | 9107 | } |
| 9096 | 9108 | {#code_end#} |
| 9097 | 9109 | {#header_close#} |
| ... | ... | @@ -9128,7 +9140,7 @@ pub fn main() void { |
| 9128 | 9140 | } |
| 9129 | 9141 | fn foo(set1: Set1) void { |
| 9130 | 9142 | const x = @errSetCast(Set2, set1); |
| 9131 | | std.debug.warn("value: {}\n", x); |
| 9143 | std.debug.warn("value: {}\n", .{x}); |
| 9132 | 9144 | } |
| 9133 | 9145 | {#code_end#} |
| 9134 | 9146 | {#header_close#} |
| ... | ... | @@ -9184,7 +9196,7 @@ pub fn main() void { |
| 9184 | 9196 | |
| 9185 | 9197 | fn bar(f: *Foo) void { |
| 9186 | 9198 | f.float = 12.34; |
| 9187 | | std.debug.warn("value: {}\n", f.float); |
| 9199 | std.debug.warn("value: {}\n", .{f.float}); |
| 9188 | 9200 | } |
| 9189 | 9201 | {#code_end#} |
| 9190 | 9202 | <p> |
| ... | ... | @@ -9208,7 +9220,7 @@ pub fn main() void { |
| 9208 | 9220 | |
| 9209 | 9221 | fn bar(f: *Foo) void { |
| 9210 | 9222 | f.* = Foo{ .float = 12.34 }; |
| 9211 | | std.debug.warn("value: {}\n", f.float); |
| 9223 | std.debug.warn("value: {}\n", .{f.float}); |
| 9212 | 9224 | } |
| 9213 | 9225 | {#code_end#} |
| 9214 | 9226 | <p> |
| ... | ... | @@ -9227,7 +9239,7 @@ pub fn main() void { |
| 9227 | 9239 | var f = Foo{ .int = 42 }; |
| 9228 | 9240 | f = Foo{ .float = undefined }; |
| 9229 | 9241 | bar(&f); |
| 9230 | | std.debug.warn("value: {}\n", f.float); |
| 9242 | std.debug.warn("value: {}\n", .{f.float}); |
| 9231 | 9243 | } |
| 9232 | 9244 | |
| 9233 | 9245 | fn bar(f: *Foo) void { |
| ... | ... | @@ -9348,7 +9360,7 @@ pub fn main() !void { |
| 9348 | 9360 | const allocator = &arena.allocator; |
| 9349 | 9361 | |
| 9350 | 9362 | const ptr = try allocator.create(i32); |
| 9351 | | std.debug.warn("ptr={*}\n", ptr); |
| 9363 | std.debug.warn("ptr={*}\n", .{ptr}); |
| 9352 | 9364 | } |
| 9353 | 9365 | {#code_end#} |
| 9354 | 9366 | When using this kind of allocator, there is no need to free anything manually. Everything |
| ... | ... | @@ -9881,7 +9893,7 @@ pub fn main() !void { |
| 9881 | 9893 | defer std.process.argsFree(std.heap.page_allocator, args); |
| 9882 | 9894 | |
| 9883 | 9895 | for (args) |arg, i| { |
| 9884 | | std.debug.warn("{}: {}\n", i, arg); |
| 9896 | std.debug.warn("{}: {}\n", .{i, arg}); |
| 9885 | 9897 | } |
| 9886 | 9898 | } |
| 9887 | 9899 | {#code_end#} |