3 ms·
Cow in general is on my shortlist for "I need to improve the docs." One area where it's used effectively in the stdlib is String::from_utf8_lossy: http://doc.r
by steveklabnik 11y ago
Cow in general is on my shortlist for "I need to improve the docs."
One area where it's used effectively in the stdlib is String::from_utf8_lossy: http://doc.rust-lang.org/collections/string/struct.String.html#method.from_utf8_lossy http://doc.rust-lang.org/collections/string/struct.String.ht...
If the argument is valid UTF-8, then no allocations need to be performed, and so the returned value will be a &str. But if it's not valid UTF-8, the replacement characters need to be inserted, which means allocation, which means String will be returned.