mintlayer-core
mintlayer-core copied to clipboard
Introduce IsEmpty derive trait
Consider following example:
struct Foo {
a: BTreeMap<u32, u32>,
b: BTreeMap<u32, u32>,
}
impl Foo {
fn is_empty(&self) -> bool {
self.a.is_empty() && self.b.is_empty()
}
}
The problem with this code is that if an additional field c is added it is easy to forget to update is_empty method.
One solution would be to write a procedural macro that would automatically iterate over fields and generate is_empty method.
Potential problem is that it should work for types that don't have 'is_empty' method like POD types. To circumvent that an attribute can be added that requires a type to implement the emptiness property.