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.
This commit is contained in:
Jonas Schäfer 2024-05-09 10:55:38 +02:00 committed by pep
parent 1449d300dd
commit 675907ba20

View file

@ -241,6 +241,20 @@ impl From<PubSubEvent> 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)]