On this page
rust/std/smart_pointers
Prev: collections | Up: std | Next: sync
Rel: rust/builtins, Ownership & Internals
Ref: Rust std — smart_pointers
Tags: #public #prog #rust #stdlib #smart_pointers #index
Import
use std::rc::Rc;
use std::sync::Arc;
use std::cell::RefCell;
use std::borrow::Cow;
Overview
Heap indirection, shared ownership, interior mutability, and clone-on-write wrappers.
Core (#tier/core)
- `Box` — Single-owner heap allocation (in prelude) used for recursive types and trait objects (
Box<dyn Error>). - `Arc` — Atomically reference-counted pointer for thread-safe shared immutable ownership (
Send + Sync).
Standard (#tier/standard)
- `Rc` — Single-threaded reference-counted pointer (faster than
Arc, notSend/Sync). - `RefCell` — Single-threaded interior mutability enforcing borrow rules at runtime (
.borrow()/.borrow_mut()).
Specialized (#tier/specialized)
- `Cow` — Clone-on-Write smart pointer avoiding heap allocation unless mutation is actually needed.
Linked from
Related notes
- tuts/rust/std Linked here; links to this page; shared tags: #index, #prog, #rust, #stdlib
- tuts/rust/std/collections Linked here; links to this page; shared tags: #index, #prog, #rust, #stdlib
- tuts/rust/std/sync Linked here; links to this page; shared tags: #index, #prog, #rust, #stdlib
- tuts/rust/std/smart_pointers/Arc Linked here; links to this page; shared tags: #prog, #rust, #stdlib
- tuts/rust/std/smart_pointers/Box Linked here; links to this page; shared tags: #prog, #rust, #stdlib
- tuts/rust/std/smart_pointers/Cow Linked here; links to this page; shared tags: #prog, #rust, #stdlib
- tuts/rust/std/smart_pointers/Rc Linked here; links to this page; shared tags: #prog, #rust, #stdlib
- tuts/rust/std/smart_pointers/RefCell Linked here; links to this page; shared tags: #prog, #rust, #stdlib
- tuts/rust/builtins Linked here; shared tags: #index, #prog, #rust
- tuts/rust/ownership_and_internals Linked here; shared tags: #index, #prog, #rust