RULES
- Borrow with
&T,&str, or slices when the callee only reads and the caller keeps ownership. - Take ownership when the callee stores, transforms, or transfers the value.
- Clone when it simplifies ownership or is required; inspect callers before removing an existing clone.
- Use
Arcfor shared ownership across threads andRcwithin one thread. Add synchronization or interior mutability only for shared mutation. - Use
Boxfor indirection, recursive types, or a deliberate layout/API requirement. Let the compiler infer lifetimes unless the public contract needs explicit ones.
Example
- ✅ Accept
&strwhen a function only reads text and does not retain it. - ❌ Clone text into a temporary value only to read it once.
Validation
Check callers before changing a public ownership signature. Run cargo check and focused tests in the target crate.
Integration
Start with rust-essentials; pair with type-driven-design when ownership changes a type invariant.