async-book icon indicating copy to clipboard operation
async-book copied to clipboard

Update src/04_pinning/01_chapter.md

Open playbahn opened this issue 1 year ago • 4 comments

Lines 243 and 244

a: test1, b: test1
a: test1, b: test1

show test1's state before and after swap, "naively". "Naively" thinking, it should be

a: test1, b: test1
a: test2, b: test2

as test1's fields are occupied by test2's field values, "naively". Lines 250 and 251

// given as in async-book
a: test1, b: test1
a: test1, b: test2

are supposed to show the actual state of test1 after swap. The actual state of test1 before and after swap is given by

println!("a: {}, b: {}", test1.a(), test1.b());
std::mem::swap(&mut test1, &mut test2);
println!("a: {}, b: {}", test1.a(), test1.b());
// println!("a: {}, b: {}", test2.a(), test2.b());

which shows lines 250 and 251 to be rectified to

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/pinning-4`
a: test1, b: test1
a: test2, b: test1

Given lines 250 and 251 are instead reproduced by

println!("a: {}, b: {}", test1.a(), test1.b());
std::mem::swap(&mut test1, &mut test2);
// println!("a: {}, b: {}", test1.a(), test1.b());
println!("a: {}, b: {}", test2.a(), test2.b());

which is not the desired code for the situation in Line 240:

Naively, we could think that what we should get a debug print of test1 two times like this:

playbahn avatar Mar 26 '24 18:03 playbahn

Sorry first time contributing

playbahn avatar Mar 26 '24 18:03 playbahn

PS it's really late at night where I live, please nobody pick this up lol

playbahn avatar Mar 26 '24 19:03 playbahn

I'll do this tomorrow

playbahn avatar Mar 26 '24 19:03 playbahn

EDIT: Proposing a change where lines 240-252 talk about test2 rather than test1

playbahn avatar Mar 27 '24 06:03 playbahn