Ownership Best Practices
Rules for APIs and data structures that work with the borrow checker instead of against it.
Search across all documentation pages
Rules for APIs and data structures that work with the borrow checker instead of against it.
redundant_clone and needless_borrow.&str, &[T], &Path for read-only inputs. Callers keep ownership; fewer moves.impl AsRef<str> at boundaries sparingly. Convenience for callers; document coercion.Cow<'a, T> for maybe-borrowed/maybe-owned text. Avoids forced allocation.&mut self methods for in-place updates. Clear exclusive access contract.RefCell/Mutex last resort.usize into Vec beats self-references.Rc until shared ownership is required. Single owner is simpler to reason about..await. Use async-aware primitives (tokio::sync).Copy only for small, stack-only types. Large Copy arrays are expensive.clone_from when reusing allocation. dst.clone_from(&src) may reuse capacity.clippy::redundant_clone. Catches needless duplicates in review.to_owned() like clone() for clarity. Pick one style per crate.'a is cognitive cost for users.'static owned captures.If profiling shows clone dominates, refactor. Otherwise clarity wins at boundaries.
Shared ownership across threads or long-lived caches with multiple handles.
Inputs: &str. Outputs: owned String unless borrowing from input is intentional and documented.
Check function signatures, new Rc/RefCell, clones in loops, and unwrap on locks.
Only when invariants prove no re-entrant borrow - document invariant.
Publish an ADR on string types, error ownership, and async state patterns.
Doctests, Miri for unsafe adjacency, loom for concurrency (advanced).
Prevents mixing indices from different registries - cheap win.
Self-referential async/state machines - follow pin crate patterns, do not invent.
Structs/enums for modeling, smart pointers when sharing is real.
Rc/Arc rulesStack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026