| Crates.io | thisisplural_derive |
| lib.rs | thisisplural_derive |
| version | 0.1.0 |
| created_at | 2021-09-11 18:15:53.65769+00 |
| updated_at | 2021-09-11 18:15:53.65769+00 |
| description | #[derive(Plural)] for creating frictionless new types with a Vec, HashMap, etc. |
| homepage | https://github.com/ryo33/thisisplural |
| repository | https://github.com/ryo33/thisisplural |
| max_upload_size | |
| id | 449815 |
| size | 6,650 |
#[derive(Plural)] for creating frictionless new types with a Vec, HashMap, etc.
#[derive(Plural)] implements From, Into, FromIterator, IntoIterator, Deref, and DerefMut.Vec and HashMap (adding other collections to here is very easy).#[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());
}