`String` is Rust’s growable text type. Its character data lives in heap-allocated memory, and Rust strings use UTF-8. That encoding lets a greeting include text such as “Grüß Gott!” or “ハロー・ワールド”. section 2.9 section 6.3.1 section 1.3.2
`String` and `&str` both represent text, but they are different types. A `String` can have text appended to it; a `str` cannot expand or shrink. You will often encounter `str` as `&str`, called a string slice. If the distinction causes type errors while you are learning, converting data to `String` is often the simpler path. section 2.9
A search starts with string literals
A small search program stores a term and a passage as string literals, walks through the passage with `.lines()`, and tests each line with `.contains(search_term)`. These methods show what text values can do, though the literals are not themselves growable `String` values. section 2.9
The type distinction also matters at function boundaries: a function accepting only `String` cannot directly take a string literal. For read-only access, a parameter constrained by `AsRef<str>` can accept either `String` or `&str`. This avoids forcing callers to use just one representation. section 6.3.1
fn is_strong<T: AsRef<str>>(password: T) -> bool { #1
password.as_ref().len() > 5
}
The password check calls `.as_ref()` before `.len()`, allowing the function to read text through a shared `str` view. section 6.3.1























