Skip to content

Commit 19f0a03

Browse files
authored
Merge pull request #1372 from michaelkirk/patch-1
prefer `length` over `size` when talking about number of elements vs. bytesize
2 parents 9477098 + f245c1c commit 19f0a03

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/primitives/array.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Arrays and Slices
22

33
An array is a collection of objects of the same type `T`, stored in contiguous
4-
memory. Arrays are created using brackets `[]`, and their size, which is known
5-
at compile time, is part of their type signature `[T; size]`.
4+
memory. Arrays are created using brackets `[]`, and their length, which is known
5+
at compile time, is part of their type signature `[T; length]`.
66

7-
Slices are similar to arrays, but their size is not known at compile time.
7+
Slices are similar to arrays, but their length is not known at compile time.
88
Instead, a slice is a two-word object, the first word is a pointer to the data,
99
and the second word is the length of the slice. The word size is the same as
1010
usize, determined by the processor architecture eg 64 bits on an x86-64.
@@ -31,8 +31,8 @@ fn main() {
3131
println!("first element of the array: {}", xs[0]);
3232
println!("second element of the array: {}", xs[1]);
3333
34-
// `len` returns the size of the array
35-
println!("array size: {}", xs.len());
34+
// `len` returns the count of elements in the array
35+
println!("number of elements in array: {}", xs.len());
3636
3737
// Arrays are stack allocated
3838
println!("array occupies {} bytes", mem::size_of_val(&xs));

0 commit comments

Comments
 (0)