From 675907ba2080b3c7a3515540555702ca71ca363d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Thu, 9 May 2024 10:55:38 +0200 Subject: [PATCH] pubsub: provide accessor function for event's source node's name Handy if you want to prefilter or distribute events based on the source node's name. --- parsers/src/pubsub/event.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/parsers/src/pubsub/event.rs b/parsers/src/pubsub/event.rs index 7dec898..1f98478 100644 --- a/parsers/src/pubsub/event.rs +++ b/parsers/src/pubsub/event.rs @@ -241,6 +241,20 @@ impl From for Element { } } +impl PubSubEvent { + /// Return the name of the node to which this event is related. + pub fn node_name(&self) -> &NodeName { + match self { + Self::Purge { node, .. } => &node, + Self::PublishedItems { node, .. } => &node, + Self::RetractedItems { node, .. } => &node, + Self::Subscription { node, .. } => &node, + Self::Delete { node, .. } => &node, + Self::Configuration { node, .. } => &node, + } + } +} + impl MessagePayload for PubSubEvent {} #[cfg(test)]