Butcher
An easy way to interact with Cow
ed structs and enums.
This crate provides the following functionalities for data wrapped in Cow
:
- destructuring/pattern matching over structs and enums,
- iterating over collections, or any type that implements
IntoIterator
, - flattening
Cow
, - removing an indirection level
Cow
.
Destructuring/pattern matching
The Butcher
trait can be used when it is necessary to destruture something
wrapped in a Cow
. Below is a simple example:
use Cow;
use Butcher;
This also allows pattern matching, as demonstrated in the following example:
use Butcher;
use Cow;
The Butcher
procedural macro can be derived for structs
and for enums.
Iteration
Here is a demonstration of how to iterate over an object wrapped in a Cow
:
use Cow;
use ;
See the documentation of CowIter
for more information.
Flattening
In some situations, the Butcher
proc macro can generate tricky fields,
such as nested Cow
. The FlattenCow
trait aims to remove such
flattening.
Removing an indirection level
The AsDerefCow
trait allows to transform a given Cow<T>
into a
Cow<<T as Deref>::Target>
. This can be usefull when it is needed to
transform a Cow<String>
into Cow<str>
.