Since beef::Cow is only compatible with str and [T], we can specialize the serde::Deserialize for Cow<str> so that it always borrows when possible. This has the advantage over std::borrow::Cow when deserializing into Cow<str> directly:
let json = r#""foo""#;
let std_cow: std::borrow::Cow<str> = serde_json::from_str(json).unwrap(); // will always deserialize to `Cow::Owned` with an allocation
let beef_cow: beef::Cow<str> = serde_json::from_str(json).unwrap(); // will be borrowed since `foo` can be borrowed from the `json` slice
Since
beef::Cow
is only compatible withstr
and[T]
, we can specialize theserde::Deserialize
forCow<str>
so that it always borrows when possible. This has the advantage overstd::borrow::Cow
when deserializing intoCow<str>
directly: