book
book copied to clipboard
ch15-06: None is for 1ˢᵗ time
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
Also I noticed, in spite of obvious intent of concise sentencing, some maybe confusing formatting.
For istance
We use the
borrow_mutmethod on theRefCell<Weak<Node>>in theparentfield ofleaf, and then we use theRc::downgradefunction to create aWeak<Node>reference tobranchfrom theRc<Node>inbranch.
Since code marked terms are recognized mainly as something from code (variable, keyword, type name, …) this sentence could be interpreted as if
reference to
branchfrom theRc<Node>inbranch.
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 withleaf.parentpointing tobranchandbranch.childrenpointing toleaf, which would cause theirstrong_countvalues 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
branchfrom theRc<Node>inbranch.
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.