1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-15 13:50:27 +02:00

Merge pull request #149 from fbornhofen/speaker-notes-string

Add speaker notes for string.md
This commit is contained in:
Martin Geisler
2023-01-10 19:55:59 +01:00
committed by GitHub

View File

@ -12,6 +12,10 @@ fn main() {
s2.push_str(&s1);
s2.push('!');
println!("s2: len = {}, capacity = {}", s2.len(), s2.capacity());
let s3 = String::from("🇨🇭");
println!("s3: len = {}, number of chars = {}", s3.len(),
s3.chars().count());
}
```
@ -20,3 +24,11 @@ fn main() {
[1]: https://doc.rust-lang.org/std/string/struct.String.html
[2]: https://doc.rust-lang.org/std/string/struct.String.html#deref-methods-str
<details>
* `len` returns the size of the `String` in bytes, not its length in characters.
* `chars` returns an iterator over the actual characters.
* `String` implements `Deref<Target = str>` which transparently gives it access to `str`'s methods.
</details>