Struct rosc::address::Matcher

source ·
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

source

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 either foo or bar
  • 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");
source

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);

Trait Implementations§

source§

impl Clone for Matcher

source§

fn clone(&self) -> Matcher

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Matcher

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.