Skip to main content

topic_matches

Function topic_matches 

Source
pub fn topic_matches(filter: &str, topic: &str) -> bool
Expand description

Returns whether an MQTT topic filter matches a topic.

+ matches exactly one level and # matches the remaining levels, including none, as the OASIS MQTT specification defines them. A filter that begins with a wildcard does not match a topic that begins with $, which MQTT reserves for server topics. A transport that delivers by topic itself, rather than through a broker, filters with this.

§Arguments

  • filter - the subscription filter, which may hold wildcards.
  • topic - the topic a message was published to.

§Returns

true when the filter selects the topic.

§Examples

use pamoja_core::topic_matches;

assert!(topic_matches("sensors/+/temperature", "sensors/1/temperature"));
assert!(topic_matches("sensors/#", "sensors"));
assert!(!topic_matches("#", "$SYS/broker/uptime"));