Kinded
Generate Rust enum kind types without boilerplate.
Get Started
use Kinded;
let drink = Coffee;
assert_eq!;
Note, the definition of DrinkKind enum was generated automatically as well as Drink::kind() method.
Kinded trait
The library provides Kinded trait:
From the example above, the derived implementation of Kinded for Drink resembles the following:
The Kinded trait allows to build abstract functions that can be used with different enum types.
Attributes
Custom kind type name
By default the kind type name is generated by adding postfix Kind to the original enum name.
This can be customized with kind = attribute:
use Kinded;
Derive traits
By default the kind type implements the following traits: Debug, Clone, Copy, PartialEq, Eq, From<T>, From<&T>.
Extra traits can be derived with derive(..) attribute:
use Kinded;
use HashSet;
let mut drink_kinds = new;
drink_kinds.insert;
A note about enum-kinds
There is a very similar crate enum-kinds that does almost the same job.
The main difference between kinded and enum-kinds crate is that kinded provides the Kinded trait, on top of which
users can implement abstract functions and use them with different enum types.
Another minor difference is that apart from From<T> and From<&T> conversions, kidned also implements kind() function on the enum type.
A note about the war in Ukraine 🇺🇦
Today I live in Berlin, I have the luxury to live a physically safe life. But I am Ukrainian. The first 25 years of my life I spent in Kharkiv, the second-largest city in Ukraine, 60km away from the border with russia. Today about a third of my home city is destroyed by russians. My parents, my relatives and my friends had to survive the artillery and air attack, living for over a month in basements.
Some of them have managed to evacuate to EU. Some others are trying to live "normal lifes" in Kharkiv, doing there daily duties. And some are at the front line right now, risking their lives every second to protect the rest.
I encourage you to donate to Charity foundation of Serhiy Prytula. Just pick the project you like and donate. This is one of the best-known foundations, you can watch a little documentary about it. Your contribution to the Ukrainian military force is a contribution to my calmness, so I can spend more time developing the project.
Thank you.
License
MIT © Serhii Potapov