liveBook · Manning

Cow

Cow is Rust’s standard-library clone-on-write type, representing either borrowed or owned data and creating owned data when necessary.

How 2 Manning books explain it

Learn Rust in a Month of Lunches

Cow is a Rust standard-library clone-on-write enum that can represent either borrowed data or owned data and create an owned copy when necessary.

How it is used
Chooses between borrowed and owned values when a function or structure may need either representation.
How deep it goes
Explains variants, generics, lifetimes, ToOwned, dynamically sized types, matching, and conversion methods.
Examples
Uses conditional message generation and User names to contrast borrowed values with allocated owned values.
What you can do after
Apply it via std::borrow::Cow to accept, return, or store borrowed and owned data in one type.

Read how Learn Rust in a Month of Lunches explains Cow →

Idiomatic Rust

Cow is Rust's standard-library copy-on-write smart pointer that can represent either borrowed data or owned data.

How it is used
Uses clone-on-write to preserve source data while allowing mutations to work on an owned value.
How deep it goes
Defines Borrowed and Owned variants, ToOwned bounds, Deref, and to_mut cloning without detailing implementation internals.
Examples
Demonstrates string replacement, a conditional loud_moo transformation, and a Cow-backed list that preserves earlier values.
What you can do after
Apply it via Rust’s standard library to mutate a Cow-backed value while leaving the source unchanged.

Read how Idiomatic Rust explains Cow →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.