Struct rosc::address::Matcher [−][src]
pub struct Matcher { /* fields omitted */ }
Expand description
With a Matcher OSC method addresses can be matched against an OSC address pattern. Refer to the OSC specification for details about OSC address spaces: http://opensoundcontrol.org/spec-1_0.html#osc-address-spaces-and-osc-addresses
Implementations
Instantiates a new Matcher
with the given address pattern.
An error will be returned if the given address pattern is invalid.
Matcher should be instantiated once per pattern and reused because its construction requires parsing the address pattern which is computationally expensive.
A valid address pattern begins with a /
and contains at least a method name, e.g. /tempo
.
OSC defines a couple of rules that look like regular expression but are subtly different:
?
matches a single character*
matches zero or more characters[a-z]
are basically regex character classes{foo,bar}
is an alternative, matching eitherfoo
orbar
- everything else is matched literally
Refer to the OSC specification for details about address pattern matching:
Examples
use rosc::address::Matcher;
Matcher::new("/tempo").expect("valid address");
Matcher::new("").expect_err("address does not start with a slash");
Match an OSC address against an address pattern.
If the address matches the pattern the result will be true
, otherwise false
.
An error is returned if the given OSC address is not valid.
A valid OSC address begins with a /
and contains at least a method name, e.g. /tempo
.
Despite OSC address patterns a plain address must not include any of the following characters #*,/?[]{}
.
Examples
use rosc::address::Matcher;
let matcher = Matcher::new("/oscillator/[0-9]/{frequency,phase}").unwrap();
assert!(matcher.match_address("/oscillator/1/frequency").unwrap());
assert!(matcher.match_address("/oscillator/8/phase").unwrap());
assert_eq!(matcher.match_address("/oscillator/4/detune").unwrap(), false);