From aecdf6ad50fef3ef68d699c2ef72b5904fdd3553 Mon Sep 17 00:00:00 2001 From: expikr <77922942+expikr@users.noreply.github.com> Date: Sat, 28 Oct 2023 07:11:56 +0800 Subject: [PATCH] Doc: elaborate on Slice section somehow the concept of slices had less elaboration in its own dedicated section than the mentions of it elsewhere. --- doc/langref.html.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 0a4d54b05f..da06a516f8 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2990,15 +2990,17 @@ pub fn main() anyerror!void { {#header_close#} {#header_open|Slices#} +

+ A slice is a pointer and a length. The difference between an array and + a slice is that the array's length is part of the type and known at + compile-time, whereas the slice's length is known at runtime. + Both can be accessed with the `len` field. +

{#code_begin|test_safety|test_basic_slices|index out of bounds#} const expect = @import("std").testing.expect; test "basic slices" { var array = [_]i32{ 1, 2, 3, 4 }; - // A slice is a pointer and a length. The difference between an array and - // a slice is that the array's length is part of the type and known at - // compile-time, whereas the slice's length is known at runtime. - // Both can be accessed with the `len` field. var known_at_runtime_zero: usize = 0; const slice = array[known_at_runtime_zero..array.len]; try expect(@TypeOf(slice) == []i32);