May 2019
Intermediate to advanced
698 pages
17h 21m
English
Cow is a smart pointer type that provides two versions of strings. It stands for Clone on Write. It has the following type signature:
pub enum Cow<'a, B> where B: 'a + ToOwned + 'a + ?Sized, { Borrowed(&'a B), Owned(<B as ToOwned>::Owned),}
First, we have the two variants:
This type is suitable for cases where one needs to avoid allocations where it's not needed. A real world example is the JSON parser crate called serde_json.
Read now
Unlock full access