Cow means “clone on write.” It can hold either borrowed data or an owned value, so code can avoid creating an owned copy until it needs one. section 11.4
enum Cow<'a, B>
where
B: 'a + ToOwned + ?Sized,
{
Borrowed(&'a B),
Owned(<B as ToOwned>::Owned),
}
The full signature shows the lifetime, the borrowed type B, the ToOwned requirement, and the Borrowed and Owned variants. section 11.4
The two variants represent different storage choices:
- Borrowed holds a reference such as &'static str when the existing data is enough. section 11.4
- Owned holds the owned form, such as String, when producing or modifying the value requires ownership. section 11.4
- into_owned and into_borrowed provide ways to change the representation when needed. section 11.4
Returning a message
A message function can return Cow<'static, str>. With no error, message.into() produces a borrowed value. With error details, format!("{message}: {info:?}").into() produces an owned String. Matching on Cow::Borrowed and Cow::Owned lets the program report which choice it made.
Storing user names
A User with name: Cow<'static, str> can hold either a string literal or an owned String. The borrowed User1 avoids an allocation, while the owned User10 keeps its allocated value.

