From 8db7da6d7ed26ac6c117564ea182b20d80d59957 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 --- data_model/src/events/data/filters.rs | 34 +++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/data_model/src/events/data/filters.rs b/data_model/src/events/data/filters.rs index 40a56d902f5..648021d30dd 100644 --- a/data_model/src/events/data/filters.rs +++ b/data_model/src/events/data/filters.rs @@ -543,23 +543,33 @@ 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) { + (DataEvent::Peer(event), Peer(filter)) => filter.matches(event), + (DataEvent::Peer(_), _) => false, + ( - 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) } - (Trigger(filter), DataEvent::Trigger(event)) => filter.matches(event), - (Role(filter), DataEvent::Role(event)) => filter.matches(event), - _ => false, + (DataEvent::Domain(DomainEvent::AssetDefinition(event)), AssetDefinition(filter)) => { + filter.matches(event) + } + (DataEvent::Domain(event), Domain(filter)) => filter.matches(event), + (DataEvent::Domain(_), _) => false, + + (DataEvent::Trigger(event), Trigger(filter)) => filter.matches(event), + (DataEvent::Trigger(_), _) => false, + + (DataEvent::Role(event), Role(filter)) => filter.matches(event), + (DataEvent::Role(_), _) => false, + + // no corresponding filters to those yet + (DataEvent::PermissionToken(_), _) => false, + (DataEvent::Configuration(_), _) => false, + (DataEvent::Executor(_), _) => false, } } }