use is_empty_derive::IsEmpty; mod is_empty { pub trait IsEmpty { fn is_empty(&self) -> bool; } impl IsEmpty for Option { fn is_empty(&self) -> bool { false } } } #[derive(IsEmpty)] struct A { a: Option, #[is_empty(if = "Vec::is_empty")] b: Vec, }