1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-04 16:16:14 +02:00

Add speaker notes for string.md

This commit is contained in:
Fabian Bornhofen 2023-01-10 19:06:06 +01:00
parent 20c0a37949
commit b2b11257f5

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().collect::<std::vec::Vec<_>>().len());
}
```
@ -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>