0.1.0 |
|
---|
#366 in #vec
7KB
151 lines
thisisplural
#[derive(Plural)]
for creating frictionless new types with a Vec, HashMap, etc.
Features
#[derive(Plural)]
implementsFrom
,Into
,FromIterator
,IntoIterator
,Deref
, andDerefMut
.- Supports
Vec
andHashMap
(adding other collections to here is very easy).
Example
#[derive(Plural)]
struct Numbers(Vec<u32>);
// use From trait
let mut my_favorite_numbers: Numbers = vec![].into();
// use DerefMut trait.
my_favorite_numbers.push(42);
// HashMap is also supported
#[derive(Plural)]
struct FavoriteNumbers(HashMap<&'static str, Numbers>);
// use FromIterator trait
let favorite_numbers = FavoriteNumbers::from_iter([("ryo33", my_favorite_numbers)]);
// use IntoIterator trait
for (name, numbers) in favorite_numbers {
// use Deref trait
println!("{} has {} favorite number(s)", name, numbers.len());
}
Dependencies
~1.5MB
~37K SLoC