Rc
Rc is Rust’s single-threaded reference-counted smart pointer for shared ownership of a value.
Code Like a Pro in Rust
Rc is Rust's single-threaded reference-counted smart-pointer type for shared ownership of a value.
- How it is used
- Uses Rc to share ownership of a value within one thread.
- How deep it goes
- Explains reference-count changes and release, contrasts atomic counters, and defers detailed Send and Sync discussion.
- Examples
- Demonstrates Rc in a doubly linked list and suggests implementing a reference-counted pointer with unsafe pointers.
- What you can do after
- Apply it via Rust’s Rc to share ownership, choosing RefCell or make_mut for different mutation needs.
Learn Rust in a Month of Lunches
Rc is Rust's reference-counting smart pointer type for shared ownership of data while tracking the number of active owning references.
- How it is used
- Shares owned data across structures or calls when unique ownership or full cloning is inconvenient.
- How deep it goes
- Explains construction, cloning, owner counts, weak references, cycles, and lifetime avoidance through worked examples.
- Examples
- Uses moved Strings, shared city names and histories, repeated function calls, owner counts, and nested city-country-world structs.
- What you can do after
- Apply it via std::rc::Rc to share data, inspect strong counts, and replace selected lifetime-heavy string references.
Also covered in
What to know first
- copyCopying is the creation of a separate representation of an existing value, object, or data, preserving some or all of its contents or state.
- borrow checkerA borrow checker is a compiler component that statically enforces ownership, borrowing, and reference-lifetime rules to prevent invalid memory access.
- garbage collectionGarbage collection is an automated process that identifies and reclaims or removes memory, data, or other items no longer reachable or needed by a system.
- heapA heap is a runtime memory region from which dynamically allocated data is obtained and whose allocation and lifetime are managed separately from function call frames.
Related concepts
- Arcalternative to · Arc is Rust’s atomically reference-counted smart pointer, which enables shared ownership of a value across threads.
- smart pointerkind of · A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.
- reference countinguses · Reference counting is a memory-management technique that tracks references to an object or value and can reclaim it when its reference count reaches zero.
- lifetime annotationaddresses · In Rust, a lifetime annotation is syntax that names or relates the validity lifetimes of references in types and function signatures.
- ownershipaddresses · Ownership is a programming-language model that assigns responsibility for a value or resource and governs its access, lifetime, and eventual cleanup.
Questions about Rc
What is Rc?
Rc is Rust’s single-threaded reference-counted smart pointer for shared ownership of a value.
Which Manning books explain Rc?
Code Like a Pro in Rust and Learn Rust in a Month of Lunches.
What should I know before learning Rc?
Manning books that teach Rc usually introduce copy, borrow checker, garbage collection and heap first.
What is the difference between Rc and Arc?
Rc is Rust’s single-threaded reference-counted smart pointer for shared ownership of a value. Arc is Rust’s atomically reference-counted smart pointer, which enables shared ownership of a value across threads.
What is Rc a kind of?
Rc is a kind of smart pointer. A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

