← ClaudeAtlas

rust-copy-on-writelisted

Use when you decide between borrowed and owned data at an API boundary, or when clone cost drives a data-structure choice. Covers Cow in return and argument position and the hit-rate rule that decides it, the to_mut double-allocation trap and its permanent flip to Owned, the lifetime a Cow struct field forces on every caller (E0515, E0521) and the into_static exit, why a Cow-backed &self -> Self API is quadratic instead of persistent, measured build, clone and index costs for Vec against the im, imbl and rpds persistent collections, the rpds !Send default, and the im RustSec advisories. Not for a profile that already names an allocation site. Triggers on "Cow", "copy-on-write", "Cow<str>", "to_mut", "into_owned", "borrowed or owned", "borrow or clone", "clone cost", "persistent collection", "immutable data structure", "structural sharing", "the im crate", "imbl", "rpds", or "zero-copy string parse".
po4yka/rust-skills · ★ 2 · Data & Documents · score 76
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