Macro typed_index_collection::impl_with_id
source · macro_rules! impl_with_id { ($ty:ty) => { ... }; }
Expand description
Implement trait WithId
automatically for a type.
The type must implement Default
and have at least 2 fields: id
and
name
. Both id
and name
will be set with the value of the input
parameter id
.
#[derive(Default)]
struct Animal {
id: String,
name: String,
species: String,
}
impl_with_id!(Animal);
let animal = Animal::with_id("cat");
assert_eq!("cat", animal.id);
assert_eq!("cat", animal.name);
assert_eq!("", animal.species);