Intermediate Rust
Q71 / 100

What is the purpose of Cow<'a, B> (Clone on Write)?

Correct! Well done.

Incorrect.

The correct answer is B) A smart pointer holding either a borrowed reference or an owned value, only cloning when mutation is needed

B

Correct Answer

A smart pointer holding either a borrowed reference or an owned value, only cloning when mutation is needed

Explanation

Cow::Borrowed(&str) avoids allocation; Cow::Owned(String) owns data. Cow::to_mut() clones only when mutation is needed. Useful for APIs accepting both &str and String.

Progress
71/100