strings

Cow for clone-on-write to avoid unnecessary allocations

Cow<'a, T> (clone on write) holds either a borrowed or owned value. It borrows when possible and clones only when mutation is needed. I use Cow<str> for APIs that might need to modify a string: if no changes are needed, it stays borrowed;

String vs &str for owned vs borrowed text

String is an owned, growable UTF-8 string on the heap. &str is a borrowed string slice, often a view into a String or a string literal. I use String when I need to own, modify, or build strings. I use &str for function parameters (accepting bo