1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-21 15:35:53 +02:00

Add note that slices can't grow (#2663)

This commit is contained in:
Nicole L 2025-02-27 12:29:03 -08:00 committed by GitHub
parent bf4e4e34ee
commit b4301e06c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>