1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-12-03 09:45:17 +02:00

Indent code in speaker notes (#476)

* Indent code in speaker notes

#475

* Update stack.md

* Update destructuring-arrays.md

* Update hashmap.md

* Update traits.md
This commit is contained in:
Charisee Chiw
2023-03-11 14:12:32 -08:00
committed by GitHub
parent 368f3ba302
commit 59d3d7f625
5 changed files with 121 additions and 122 deletions

View File

@@ -31,20 +31,20 @@ fn main() {
* We can inspect the memory layout with `unsafe` code. However, you should point out that this is rightfully unsafe!
```rust,editable
fn main() {
let mut s1 = String::from("Hello");
s1.push(' ');
s1.push_str("world");
// DON'T DO THIS AT HOME! For educational purposes only.
// String provides no guarantees about its layout, so this could lead to
// undefined behavior.
unsafe {
let (capacity, ptr, len): (usize, usize, usize) = std::mem::transmute(s1);
println!("ptr = {ptr:#x}, len = {len}, capacity = {capacity}");
```rust,editable
fn main() {
let mut s1 = String::from("Hello");
s1.push(' ');
s1.push_str("world");
// DON'T DO THIS AT HOME! For educational purposes only.
// String provides no guarantees about its layout, so this could lead to
// undefined behavior.
unsafe {
let (capacity, ptr, len): (usize, usize, usize) = std::mem::transmute(s1);
println!("ptr = {ptr:#x}, len = {len}, capacity = {capacity}");
}
}
}
```
```
</details>