1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/// Implements the Id trait for an object. For example, if an object Animal has
/// a field 'species_id' which is a pointer toward another Object of type
/// Species, you can implements Id with the following example. You can also
/// implement Id for Animal itself (the identifier of an Animal is its own
/// field that must be named `id`).
/// ```
/// # use typed_index_collection::impl_id;
/// # fn main() {
/// struct Species {
/// id: String,
/// name: String,
/// }
/// struct Animal {
/// id: String,
/// name: String,
/// species_id: String,
/// }
/// impl_id!(Animal, Species, species_id);
/// impl_id!(Animal);
/// # }
/// ```
/// 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`.
/// ```
/// # use typed_index_collection::{impl_with_id, WithId};
/// # fn main() {
/// #[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);
/// # }
/// ```