This crate provides a more generalized copy-on-write type, that strives to be a drop-in replacement for std::borrow::Cow.
Because the standard library's Cow is designed in a way where both the owning and borrowed type reference each other via ToOwned and Borrow, it is not possible to implement Cow for types that do not have this relationship. For example, providing custom implementations for storing a borrowed str.
This crate's Cow type mimics the API of std::borrow::Cow, but only requires that the owning type implements Borrow, From, and optionally BorrowMut. To clone the owned type from the borrowed type, the owning type must implement From for the borrowed type reference.
This Cow type likely requires one or both types to be marked in the type as this cannot be inferred from the traits alone.
For convenience, grass_chewer::Cow implements From for std::borrow::Cow and &std::borrow::Cow and Into for std::borrow::Cow when the std feature is enabled, so it can be easily swapped between the two implementations for compatibility.
To make sure transitions between the two implementations don't cause cloning, .into() and From require that the underlying owning type is the same as the standard library's owning type. Passing references to constructors can be used to convert between the types when only the borrowed type is the same.