rust-copy-on-writelisted
Install: claude install-skill po4yka/rust-skills
# Rust copy-on-write
## Purpose
Decide whether to copy at all. This skill covers the choice between a borrow and an owned
value at an API boundary (`Cow`), and the choice of a data structure when clone cost drives
the design (persistent collections, and the crates that supply them). It answers the question
that comes before a profile: which shape do I give this signature.
It stops where `rust-hot-path` starts. Once a profile names an allocation site, go there for
capacity, buffer reuse, `SmallVec`, and `Arc::make_mut`. This skill also leaves atomics and
shared-memory ordering to `memory-model`.
Every number below was measured on rustc 1.97.0, edition 2024, aarch64-apple-darwin, release
profile, with the counting allocator in the next section. Allocation counts repeat exactly
across runs. Times do not; a range is the observed range. Re-measure on your target.
## Route the decision to a section
| You are about to | Go to |
| --- | --- |
| Return `String` where most calls change nothing | [`Cow` in return position](#cow-in-return-position) |
| Chain two or more string or slice transforms | [`Cow` in argument position](#cow-in-argument-position) |
| Write `cow.to_mut()` in front of a method | [`to_mut()`](#to_mut-is-for-mut-self-methods-only) |
| Put a `Cow` field in a struct | [A `Cow` field infects the struct](#a-cow-field-infects-the-struct-with-a-lifetime) |
| Write `Cow<'_, String>`, or any `impl Borrow<..>` | [The `Cow` parameter is the borrowed half](#the-cow-paramet