From fb54f9dffbb8e23a8a934d7f66db540178274811 Mon Sep 17 00:00:00 2001 From: Nikita Strygin Date: Wed, 6 Mar 2024 11:38:53 +0300 Subject: [PATCH] [refactor] #1981, #4195, #3068: match more exhaustively over events in DataEventFilter This will produce a compile error in case a new top-level data event is introduced. It will not catch new Domain event types (like Account, Asset, AssetDefinition). Achieving that will require listing all (even non-hierarchical) event types, which is probably too much boilerplate Signed-off-by: Nikita Strygin [refactor] #1981, #4195, #3068: match more exhaustively over events in DataEventFilter This will produce a compile error in case a new top-level data event is introduced. It will not catch new Domain event types (like Account, Asset, AssetDefinition). Achieving that will require listing all (even non-hierarchical) event types, which is probably too much boilerplate Signed-off-by: Nikita Strygin --- data_model/src/events/data/filters.rs | 44 +++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/data_model/src/events/data/filters.rs b/data_model/src/events/data/filters.rs index a9c67c1472f..34bf7e5db39 100644 --- a/data_model/src/events/data/filters.rs +++ b/data_model/src/events/data/filters.rs @@ -557,23 +557,43 @@ impl EventFilter for DataEventFilter { fn matches(&self, event: &DataEvent) -> bool { use DataEventFilter::*; - match (self, event) { - (Any, _) => true, - (Peer(filter), DataEvent::Peer(event)) => filter.matches(event), - (Domain(filter), DataEvent::Domain(event)) => filter.matches(event), - (Account(filter), DataEvent::Domain(DomainEvent::Account(event))) => { - filter.matches(event) - } + match (event, self) { ( - Asset(filter), DataEvent::Domain(DomainEvent::Account(AccountEvent::Asset(event))), + Asset(filter), ) => filter.matches(event), - (AssetDefinition(filter), DataEvent::Domain(DomainEvent::AssetDefinition(event))) => { + (DataEvent::Domain(DomainEvent::Account(event)), Account(filter)) => { + filter.matches(event) + } + (DataEvent::Domain(DomainEvent::AssetDefinition(event)), AssetDefinition(filter)) => { filter.matches(event) } - (Trigger(filter), DataEvent::Trigger(event)) => filter.matches(event), - (Role(filter), DataEvent::Role(event)) => filter.matches(event), - _ => false, + (DataEvent::Domain(event), Domain(filter)) => filter.matches(event), + + (DataEvent::Peer(event), Peer(filter)) => filter.matches(event), + (DataEvent::Trigger(event), Trigger(filter)) => filter.matches(event), + (DataEvent::Role(event), Role(filter)) => filter.matches(event), + + ( + DataEvent::Peer(_) + | DataEvent::Domain(_) + | DataEvent::Trigger(_) + | DataEvent::Role(_) + | DataEvent::PermissionToken(_) + | DataEvent::Configuration(_) + | DataEvent::Executor(_), + Any, + ) => true, + ( + DataEvent::Peer(_) + | DataEvent::Domain(_) + | DataEvent::Trigger(_) + | DataEvent::Role(_) + | DataEvent::PermissionToken(_) + | DataEvent::Configuration(_) + | DataEvent::Executor(_), + _, + ) => false, } } }