File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -2990,15 +2990,17 @@ pub fn main() anyerror!void {
2990
2990
{#header_close#}
2991
2991
2992
2992
{#header_open|Slices#}
2993
+ <p>
2994
+ A slice is a pointer and a length. The difference between an array and
2995
+ a slice is that the array's length is part of the type and known at
2996
+ compile-time, whereas the slice's length is known at runtime.
2997
+ Both can be accessed with the `len` field.
2998
+ </p>
2993
2999
{#code_begin|test_safety|test_basic_slices|index out of bounds#}
2994
3000
const expect = @import("std").testing.expect;
2995
3001
2996
3002
test "basic slices" {
2997
3003
var array = [_]i32{ 1, 2, 3, 4 };
2998
- // A slice is a pointer and a length. The difference between an array and
2999
- // a slice is that the array's length is part of the type and known at
3000
- // compile-time, whereas the slice's length is known at runtime.
3001
- // Both can be accessed with the `len` field.
3002
3004
var known_at_runtime_zero: usize = 0;
3003
3005
const slice = array[known_at_runtime_zero..array.len];
3004
3006
try expect(@TypeOf(slice) == []i32);
You can’t perform that action at this time.
0 commit comments