diff options
| author | Tshepang Lekhonkhobe <tshepang@gmail.com> | 2015-07-05 13:30:46 +0200 |
|---|---|---|
| committer | Tshepang Lekhonkhobe <tshepang@gmail.com> | 2015-07-05 13:33:06 +0200 |
| commit | f82276d947533cd70b4cf5472dc14ba59421144b (patch) | |
| tree | 1012e09a102c02ba49d62de4efc9a5f83747af29 /src/doc | |
| parent | 912ab64a0de2c121a1c9f10bb1dbe75983b78c73 (diff) | |
| download | rust-f82276d947533cd70b4cf5472dc14ba59421144b.tar.gz rust-f82276d947533cd70b4cf5472dc14ba59421144b.zip | |
reference: improve examples of the different array types
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/reference.md | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index a3e13acccae..d692171f5f2 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3344,12 +3344,17 @@ heap. A slice is a 'view' into an array. It doesn't own the data it points to, it borrows it. -An example of each kind: +Examples: ```{rust} -let vec: Vec<i32> = vec![1, 2, 3]; -let arr: [i32; 3] = [1, 2, 3]; -let s: &[i32] = &vec[..]; +// A stack-allocated array +let array: [i32; 3] = [1, 2, 3]; + +// A heap-allocated array +let vector: Vec<i32> = vec![1, 2, 3]; + +// A slice into an array +let slice: &[i32] = &vector[..]; ``` As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The |
