3 ms·
> if String could point to either &'static str or an owned buffer, That used to be the purpose of MaybeOwned, which was just replaced by CowString (a typedef o
by masklinn 12y ago
> if String could point to either &'static str or an owned buffer,
That used to be the purpose of MaybeOwned, which was just replaced by CowString (a typedef of Cow to String and str).
On Cow, a deref returns an immutable slice (with no copy) so slice methods can be called directly on the CowString, `to_mut` copies the source data if necessary and returns a mutable ref, and `into_owned` copies the source data if necessary and returns it.
So if you don't really care what you get and whether it's going to be copied or whatever, ask for a CowString and go to town.