January 2019
Beginner to intermediate
554 pages
13h 31m
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