Cow<'a, str> is a Rust enum that efficiently handles both borrowed string slices and owned strings, cloning only when modification is required.
There is no Cow str type in Rust; the correct type is Cow<'a, str>, which is an enum from the standard library that represents either an owned String or a borrowed string slice. Use Cow::Borrowed for existing slices to avoid allocation, or Cow::Owned when you need to modify the string.
use std::borrow::Cow;
let borrowed: Cow<str> = Cow::Borrowed("hello");
let mut owned: Cow<str> = Cow::Owned(String::from("world"));
owned.to_mut().push_str("!");
Cow stands for "Clone on Write" and is a smart way to handle text that might be borrowed or owned. It lets you work with a string slice without copying it, but if you need to change the text, it automatically creates a new owned copy. Think of it like borrowing a book from a library: you can read it as-is, but if you need to write notes in it, you must buy your own copy first.