Skip to main content

matches

Function matches 

Source
pub fn matches(pattern: &str, key: &str) -> bool
Expand description

Returns whether a concrete key is selected by a pattern key expression.

§Arguments

  • pattern - the key expression to test against; it may contain wildcards.
  • key - the concrete key being routed; it must be valid and carry no wildcards.

§Returns

true if key is one of the keys pattern selects. Returns false if pattern is not a valid key expression, or if key is not a valid concrete key.

§Examples

use pamoja_zenoh::keyexpr::matches;

assert!(matches("room275/*/temperature", "room275/device1/temperature"));
assert!(!matches("room275/*/temperature", "room275/temperature")); // `*` needs one chunk
assert!(matches("organizationA/**/temperature", "organizationA/temperature")); // `**` allows none
assert!(matches("thermometer$*/temperature", "thermometer1/temperature"));