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
sourceimpl 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:
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("/oscillator/1/frequency").unwrap()));
assert!(matcher.match_address(OscAddress::new("/oscillator/8/phase").unwrap()));
assert_eq!(matcher.match_address(OscAddress::new("/oscillator/4/detune").unwrap()), false);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Matcher
impl Send for Matcher
impl Sync for Matcher
impl Unpin for Matcher
impl UnwindSafe for Matcher
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more