Skip to content

Commit aecdf6a

Browse files
author
expikr
authored
Doc: elaborate on Slice section
somehow the concept of slices had less elaboration in its own dedicated section than the mentions of it elsewhere.
1 parent 1c85b0a commit aecdf6a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

doc/langref.html.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,15 +2990,17 @@ pub fn main() anyerror!void {
29902990
{#header_close#}
29912991

29922992
{#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>
29932999
{#code_begin|test_safety|test_basic_slices|index out of bounds#}
29943000
const expect = @import("std").testing.expect;
29953001

29963002
test "basic slices" {
29973003
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.
30023004
var known_at_runtime_zero: usize = 0;
30033005
const slice = array[known_at_runtime_zero..array.len];
30043006
try expect(@TypeOf(slice) == []i32);

0 commit comments

Comments
 (0)