rust-syntax-smart-pointers
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
rust-syntax-smart-pointers
Owning pointers and shared-ownership primitives: Box<T>, Rc<T>, Arc<T>, RefCell<T>, Cell<T>, OnceCell<T>, OnceLock<T>, LazyLock<T>, Weak<T>, and a Pin<T> overview. Each picks a different combination of: heap allocation, single-vs-multi-thread refcounting, interior mutability, and lazy initialization. Choosing wrongly leaks, deadlocks, panics, or fails to compile.
Cross-references: [[rust-core-memory-model]] (stack vs heap, UnsafeCell), [[rust-syntax-borrowing]] (the borrow rules RefCell enforces at runtime), [[rust-syntax-async-await]] (Pin<&mut Self> in Future::poll; deep pinning reference under that skill), [[rust-impl-concurrency]] (Arc<Mutex<T>> vs atomics in real workloads).
When to use this skill
- User reaches for
Box<T>for a recursive type (tree, linked list) or adyn Traitreturn. - User wants to share read-only data across a single thread (
Rc<T>) or across threads (Arc<T>). - User asks "how do I mutate through a shared reference" and needs to choose
Cell/RefCell/Mutex/RwLock/Atomic*. - User wants a lazily-initialized global and is tempted to use
static mutorlazy_static!. - User builds a graph / observer / parent-child tree and hits a reference cycle (memory leak with
Rc<RefCell<T>>). - User sees
Future::poll(self: Pin<&mut Self>, ...)and asks "what isPin".