pub fn from_str(input: &str) -> Result<Interval, IntervalError> {
        lazy_static! {
            static ref RE: Regex = Regex::new("^(?P<quality>([MmPpDd]|[Aa]+|[Dd]+))(?P<size>([Uu]|\\d+))$").unwrap();
        }
        let caps = RE.captures(input).unwrap();
        if let (Some(quality), Some(size)) = (caps.name("quality"), caps.name("size")) {
            let quality = quality.as_str();
            let quality = match quality.chars().next().unwrap() {
                'M' => IntervalQuality::Major,
                'm' => IntervalQuality::Minor,
                'P' | 'p' => IntervalQuality::Perfect,
                'A' | 'a' => IntervalQuality::Augmented(quality.len() - 1),
                'D' | 'd' => IntervalQuality::Diminished(quality.len() - 1),
                _ => panic!("Interval parsing regex is broken"),
            };
            let size = match size.as_str() {
                "U" | "u" => Ok(IntervalSize::Unison),
                numeric => {
                    let interval_size = numeric.parse::<usize>().map_err(|_| IntervalError::InvalidToken)?;
                    let interval_size = if interval_size == 0 { 0 } else { interval_size - 1 };
                    match interval_size {
                        0..=6 => Ok(IntervalSize::from_diatonic_size(interval_size)),
                        _ => Err(IntervalError::UnsupportedCompoundInterval),
                    }
                },
            }?;
            Interval::new(size, quality)
        } else {
            Err(IntervalError::InvalidQualityAndSizeCombination)
        }
    }
/// Instantiate an `Interval` using the shorthand documented in [`crate::primitives`]. If the token cannot be
/// parsed or the desired interval is invalid, an error will be returned.
Instantiate an `Interval` using the shorthand documented in [`crate::primitives`]. If the token cannot be
parsed or the desired interval is invalid, an error will be returned.
Instantiate an ` Interval ` using the shorthand documented in [ ` crate :: primitives ` ] . If the token cannot be parsed or the desired interval is invalid an error will be returned .
pub fn from_str(input: &str) -> Result<Interval, IntervalError> {
        lazy_static! {
            static ref RE: Regex = Regex::new("^(?P<quality>([MmPpDd]|[Aa]+|[Dd]+))(?P<size>([Uu]|\\d+))$").unwrap();
        }
        let caps = RE.captures(input).unwrap();
        if let (Some(quality), Some(size)) = (caps.name("quality"), caps.name("size")) {
            let quality = quality.as_str();
            let quality = match quality.chars().next().unwrap() {
                'M' => IntervalQuality::Major,
                'm' => IntervalQuality::Minor,
                'P' | 'p' => IntervalQuality::Perfect,
                'A' | 'a' => IntervalQuality::Augmented(quality.len() - 1),
                'D' | 'd' => IntervalQuality::Diminished(quality.len() - 1),
                _ => panic!("Interval parsing regex is broken"),
            };
            let size = match size.as_str() {
                "U" | "u" => Ok(IntervalSize::Unison),
                numeric => {
                    let interval_size = numeric.parse::<usize>().map_err(|_| IntervalError::InvalidToken)?;
                    let interval_size = if interval_size == 0 { 0 } else { interval_size - 1 };
                    match interval_size {
                        0..=6 => Ok(IntervalSize::from_diatonic_size(interval_size)),
                        _ => Err(IntervalError::UnsupportedCompoundInterval),
                    }
                },
            }?;
            Interval::new(size, quality)
        } else {
            Err(IntervalError::InvalidQualityAndSizeCombination)
        }
    }
pub fn from_str ( input : & str ) -> Result < Interval , IntervalError > { lazy_static ! { static ref RE Regex Regex new ( " \\ " ) unwrap ( ) } let caps = RE . captures ( input ) . unwrap ( ) ; if let ( Some ( quality ) , Some ( size ) ) = ( caps . name ( " " ) , caps . name ( " " ) ) { let quality = quality . as_str ( ) ; let quality = match quality . chars ( ) . next ( ) . unwrap ( ) { 'M' => IntervalQuality :: Major , 'm' => IntervalQuality :: Minor , 'P' | 'p' => IntervalQuality :: Perfect , 'A' | 'a' => IntervalQuality :: Augmented ( quality . len ( ) - 1 ) , 'D' | 'd' => IntervalQuality :: Diminished ( quality . len ( ) - 1 ) , _ => panic ! ( " " ) , } ; let size = match size . as_str ( ) { " " | " " => Ok ( IntervalSize :: Unison ) , numeric => { let interval_size = numeric . parse :: < usize > ( ) . map_err ( | _ | IntervalError :: InvalidToken ) ? ; let interval_size = if interval_size == 0 { 0 } else { interval_size - 1 } ; match interval_size { 0 ..= 6 => Ok ( IntervalSize :: from_diatonic_size ( interval_size ) ) , _ => Err ( IntervalError :: UnsupportedCompoundInterval ) , } } , } ? ; Interval :: new ( size , quality ) } else { Err ( IntervalError :: InvalidQualityAndSizeCombination ) } }
Instantiate an `Interval` using the shorthand documented in [`crate::primitives`].
Instantiate an ` Interval ` using the shorthand documented in [ ` crate :: primitives ` ] .
input
&str