book icon indicating copy to clipboard operation
book copied to clipboard

ch15-06: None is for 1ˢᵗ time

Open deep-outcome opened this issue 3 years ago • 1 comments

Listing 15-29 has only 1 println!("leaf parent = {:?}", leaf.parent.borrow().upgrade());. Thus None option shows in output just once by end — leaf parent = None — not “again”.

leaf strong = 1, weak = 0
branch strong = 1, weak = 1
leaf strong = 2, weak = 0
leaf parent = None
leaf strong = 1, weak = 0

deep-outcome avatar Sep 11 '22 21:09 deep-outcome

Also I noticed, in spite of obvious intent of concise sentencing, some maybe confusing formatting.

For istance

We use the borrow_mut method on the RefCell<Weak<Node>> in the parent field of leaf, and then we use the Rc::downgrade function to create a Weak<Node> reference to branch from the Rc<Node> in branch.

Since code marked terms are recognized mainly as something from code (variable, keyword, type name, …) this sentence could be interpreted as if

reference to branch from the Rc<Node> in branch.

is not meant as reference to branch somewhere in heap but to branch residing at stack — that which is visually available in code sample.

Anoter one is

We know it can’t contain an Rc<T>, because that would create a reference cycle with leaf.parent pointing to branch and branch.children pointing to leaf, which would cause their strong_count values to never be 0.

that could be seen in same manner as if branch and leaf denotes exact points in stack — not some places at heap.

While Rc<T> refers only to heap, it seems this okay but still I wonder if this is really intentional or if misuse is overseen due following concise writing. Once again I mean that

reference to branch from the Rc<Node> in branch.

uses 1ˢᵗ time branch to refer to heap allocated data and in turn 2ⁿᵈ time branch refers to variable at stack.

Again, I find this fine. Just wondering if it is intentional. I would fix it immediately if were sure about it. There is quite lot of these.

deep-outcome avatar Sep 11 '22 21:09 deep-outcome