Skip to content

Commit b4301e0

Browse files
authored
Add note that slices can't grow (#2663)
1 parent bf4e4e3 commit b4301e0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/references/slices.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ fn main() {
4242
- Slices always borrow from another object. In this example, `a` has to remain
4343
'alive' (in scope) for at least as long as our slice.
4444

45+
- You can't "grow" a slice once it's created:
46+
- You can't append elements of the slice, since it doesn't own the backing
47+
buffer.
48+
- You can't grow a slice to point to a larger section of the backing buffer.
49+
The slice loses information about the underlying buffer and so you can't
50+
know how larger the slice can be grown.
51+
- To get a larger slice you have to back to the original buffer and create a
52+
larger slice from there.
53+
4554
</details>

0 commit comments

Comments
 (0)