pub struct Matcher {
pub pattern: String,
/* private fields */
}
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
Fields§
§pattern: String
Implementations§
source§impl Matcher
impl Matcher
sourcepub fn new(pattern: &str) -> Result<Self, OscError>
pub fn new(pattern: &str) -> Result<Self, OscError>
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: https://opensoundcontrol.stanford.edu/spec-1_0.html#osc-message-dispatching-and-pattern-matching.
Examples
use rosc::address::Matcher;
Matcher::new("/tempo").expect("valid address");
Matcher::new("").expect_err("address does not start with a slash");
sourcepub fn match_address(&self, address: &OscAddress) -> bool
pub fn match_address(&self, address: &OscAddress) -> bool
Match an OSC address against an address pattern.
If the address matches the pattern the result will be true
, otherwise false
.
Examples
use rosc::address::{Matcher, OscAddress};
let matcher = Matcher::new("/oscillator/[0-9]/{frequency,phase}").unwrap();
assert!(matcher.match_address(&OscAddress::new(String::from("/oscillator/1/frequency")).unwrap()));
assert!(matcher.match_address(&OscAddress::new(String::from("/oscillator/8/phase")).unwrap()));
assert_eq!(matcher.match_address(&OscAddress::new(String::from("/oscillator/4/detune")).unwrap()), false);