| ... | ... | @@ -2975,8 +2975,10 @@ test "using slices for strings" { |
| 2975 | 2975 | const world: []const u8 = "世界"; |
| 2976 | 2976 | |
| 2977 | 2977 | var all_together: [100]u8 = undefined; |
| 2978 | | // You can use slice syntax on an array to convert an array into a slice. |
| 2979 | | const all_together_slice = all_together[0..]; |
| 2978 | // You can use slice syntax with at least one runtime-know index on an |
| 2979 | // array to convert an array into a slice. |
| 2980 | var start : usize = 0; |
| 2981 | const all_together_slice = all_together[start..]; |
| 2980 | 2982 | // String concatenation example. |
| 2981 | 2983 | const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world }); |
| 2982 | 2984 | |
| ... | ... | @@ -3002,7 +3004,8 @@ test "slice pointer" { |
| 3002 | 3004 | // The slice is mutable because we sliced a mutable pointer. |
| 3003 | 3005 | try expect(@TypeOf(slice) == []u8); |
| 3004 | 3006 | |
| 3005 | | // Again, slicing with constant indexes will produce another pointer to an array: |
| 3007 | // Again, slicing with comptime-known indexes will produce another pointer |
| 3008 | // to an array: |
| 3006 | 3009 | const ptr2 = slice[2..3]; |
| 3007 | 3010 | try expect(ptr2.len == 1); |
| 3008 | 3011 | try expect(ptr2[0] == 3); |