adambard / adambard/learnxinyminutes-docs

[en/rust] Emphasize the difference between &str and String.

Open
#4,105 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.