Vec of Enum
A helper struct to manage a Vec
of enum
values. Reduces boilerplate, implements useful traits.
let mut errors = default;
// ❌ Without `vec-of-enum`: too verbose
errors.push;
// ✅ With `vec-of-enum`: very concise
errors.push;
Full example
use ;
use ;
// Define some sample validation error structs
// Define an enum that can contain any validation error
// Convenience conversion
// Define a typed vector wrapper for ValidationErrors
define!;
// Define a typed vector wrapper that also automatically converts from variant types
define!;
let mut errors = default;
// ❌ Without `vec-of-enum`: too verbose
errors.push;
// ✅ With `vec-of-enum`: very concise
errors.push;
Features
The wrapper struct created using the define!
macro:
- Is
#[repr(transparent)]
for zero-cost abstraction - Implements
Deref
andDerefMut
toVec<T>
for access to all Vec methods - Provides
new()
,push()
, andextend_from()
methods - Implements
Default
,Extend
,IntoIterator
,From<Vec<T>>
, andInto<Vec<T>>
- Supports automatic conversions from variant types when using the
variants = [...]
option
Custom Derives
You can add any derive macros to your struct definition, and they will be applied to the generated struct. For example:
use ;
define!;
This allows you to add any necessary derives that your application requires.
Installation
cargo add vec-of-enum
Gratitude
Like the project? ⭐ Star this repo on GitHub!
License
Apache-2.0 or MIT.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as above, without any additional terms or conditions.