Skip to content

Commit

Permalink
[refactor] #1981, #4195, #3068: match more exhaustively over events i…
Browse files Browse the repository at this point in the history
…n 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 <[email protected]>
  • Loading branch information
DCNick3 committed Mar 6, 2024
1 parent 560a1ab commit 225f68f
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions data_model/src/events/data/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down

0 comments on commit 225f68f

Please sign in to comment.