Skip to content

Commit

Permalink
Add note that slices can't grow (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison authored Feb 27, 2025
1 parent bf4e4e3 commit b4301e0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/references/slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ fn main() {
- Slices always borrow from another object. In this example, `a` has to remain
'alive' (in scope) for at least as long as our slice.

- You can't "grow" a slice once it's created:
- You can't append elements of the slice, since it doesn't own the backing
buffer.
- You can't grow a slice to point to a larger section of the backing buffer.
The slice loses information about the underlying buffer and so you can't
know how larger the slice can be grown.
- To get a larger slice you have to back to the original buffer and create a
larger slice from there.

</details>

0 comments on commit b4301e0

Please sign in to comment.