adambard / adambard/learnxinyminutes-docs
[en/rust] Emphasize the difference between &str and String.
- Dominant language
- Markdown
- Stars
- 12.3k
- Forks
- 3.7k
- Avg merge
- 13h 10m
- Merged PRs (30d)
- 6
Description
The difference between a heap allocated `String` and a Slice `&str` is not emphasized properly.
As already mentioned a `String` is a heap allocated String. In addition it should be clearly emphasized, that a `String` is a vector of bytes and always holds a valid UTF-8 sequence. Its growable and does not hold a null termination character!
When it comes to `&str` I miss a comment about the fact, that slices are allocates in read-only-memory. The association between a heap allocated string and a slice needs to be explained in detail:
A slice is a `&[u8]` and points to a valid UTF-8 sequence, and can be used to view into a String. A `&[T] ` is a view into `Vec`.
Especially for a Rust-beginner these side notes can be very useful for a deeper understanding.
Contributor guide
Assessment
This issue has not been assessed yet.