Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch15-06: None is for 1ˢᵗ time #3344

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

deep-outcome
Copy link
Contributor

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

`None` shows for 1st time in execution.
@deep-outcome
Copy link
Contributor Author

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.

@carols10cents carols10cents added this to the ch15 milestone Sep 13, 2022
@deep-outcome deep-outcome changed the title None is for 1ˢᵗ time ch15-06: None is for 1ˢᵗ time Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants