String vs str

    Rust terminology:

    • an immutable reference to a string slice.
    • String a mutable string buffer.

    • Rust’s String type is a wrapper around a vector of bytes. As with a Vec<T>, it is owned.

    • As with many other types creates a string from a string literal; String::new() creates a new empty string, to which string data can be added using the push() and push_str() methods.

    • You can borrow slices from String via & and optionally range selection.

    • For C++ programmers: think of &str as const char* from C++, but the one that always points to a valid string in memory. Rust String is a rough equivalent of from C++ (main difference: it can only contain UTF-8 encoded bytes and will never use a small-string optimization).