I would to use
Cow<&str> with Serde to avoid extra-allocations.
I decided to learn about
Cow and went to read the docs.
I played with
Cow::to_mut and noticed strange thing which as I guess means I misunderstand something.
So, we have https://doc.rust-lang.org/std/borrow/enum.Cow.html#method.to_mut with the test inlined.
The test asserts that
assert_eq!( cow, Cow::Owned(String::from("FOO")) as Cow<str> );
However, if I make an opposite test it passes too
assert_eq!( cow, Cow::Borrowed(&String::from("FOO")) // Or just Cow::Borrowed("FOO") );
How is it possible for
Cow to be both
Owned? Where is a trick here?