1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-10 00:44:21 +02:00

Merge pull request #166 from rastringer/patch-1

Adds speaker notes for 6.4.1. String vs str
This commit is contained in:
Andrew Walbran 2023-01-13 14:05:19 +00:00 committed by GitHub
commit 74e2ba6acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,3 +18,15 @@ Rust terminology:
* `&str` an immutable reference to a string slice. * `&str` an immutable reference to a string slice.
* `String` a mutable string buffer. * `String` a mutable string buffer.
<details>
* `&str` introduces a string slice, which is an immutable reference to UTF-8 encoded string data stored in a block of memory. String literals (`”Hello”`), are stored in the program’s binary.
* Rust’s `String` type is a wrapper around a vector of bytes. As with a `Vec<T>`, it is mutable and owned.
* `String::from` creates a string from a string literal; `String::new` creates a new empty string, to which string data can be added using the `to_string` method.
* The `push_str` method appends a string slice to the string.
</details>