David Drysdale, in "Effective Rust" about smart pointers

⚓ Rust    📅 2026-01-27    👤 surdeus    👁️ 1      

surdeus

I just read the section about smart pointers, and might have found three issues:

First, they say in Item 8: Familiarize yourself with reference and pointer types - Effective Rust about Weak<T>

The underlying item is dropped when the strong reference count drops to zero, but the bookkeeping structure is dropped only when the weak reference count also drops to zero.

That statement is a bit weak: "dropped" is here used twice, but not explained in detail, and I think the "bookkeeping structure" is not distinct from the actual payload, so the explanation is a bit unclear. Can you explain it in some more detail, e.g. when does the actual de-allocation occur?

Next tiny issue is

An Rc on its own gives you the ability to reach an item in different ways,

Here, I think the singular "An" is used wrong. For "different ways" we would need more than one single RC? How could we rephrase the statement?

Last issue or question is to the diagram Figure 1-8: Why have b1 and b2 to contain and use two pointers each, one pointing to the borrow count, and one to the payload. The borrow count should have a fixed size (of usize) so we know the offset to the payload and would need only one pointer each?

3 posts - 3 participants

Read full topic

🏷️ Rust_feed