fn parse_edge(&mut self) -> CdResult<Option<Edge>> {
        let mut numerator = None;
        let (mut init_idx, c) = self.peek().expect("Slice can't be empty!");

        // If the next character is not numeric, this means this isn't an edge
        // at all, and we return None.
        if !matches!(c, '0'..='9') {
            return Ok(None);
        }

        let mut end_idx = init_idx;

        // We read through the diagram until we encounter something that
        // looks like the start of a node.
        loop {
            let (idx, c) = self.peek_or()?;

            match c {
                // If we're dealing with a fraction:
                '/' => {
                    // Parse and save the numerator.
                    numerator = Some(self.parse_slice(init_idx, end_idx)?);

                    // Reset what's being read.
                    init_idx = idx + 1;
                }

                // If we reached the next node.
                '(' | '*' | ' ' | 'A'..='z' => {
                    // Parse the last value (either the denominator in case of a
                    // fraction, or the single number otherwise).
                    let last = self.parse_slice(init_idx, end_idx)?;

                    return Ok(Some(match numerator {
                        Some(num) => Edge::rational(num, last, end_idx)?,
                        None => Edge::int(last, end_idx)?,
                    }));
                }

                // Business as usual.
                '0'..='9' => {}

                // We found an unexpected symbol.
                _ => return Err(CdError::InvalidSymbol { pos: idx }),
            }

            end_idx = idx;
            self.next();
        }
    }
/// Parses the next edge in the Coxeter diagram. May return `None` if
/// there's currently no edge to be read.
///
/// # Errors
/// This method will return a [`CdError::InvalidSymbol`] if it ever
/// encounters any unexpected symbol. Likewise, it will return a
/// [`CdError::InvalidEdge`] if the edge is something invalid like `1/0`.
Parses the next edge in the Coxeter diagram. May return `None` if
there's currently no edge to be read.
Parses the next edge in the Coxeter diagram . May return ` None ` if there ' s currently no edge to be read .
fn parse_edge(&mut self) -> CdResult<Option<Edge>> {
        let mut numerator = None;
        let (mut init_idx, c) = self.peek().expect("Slice can't be empty!");
        // If the next character is not numeric, this means this isn't an edge
        // at all, and we return None.
        if !matches!(c, '0'..='9') {
            return Ok(None);
        }
        let mut end_idx = init_idx;
        // We read through the diagram until we encounter something that
        // looks like the start of a node.
        loop {
            let (idx, c) = self.peek_or()?;
            match c {
                // If we're dealing with a fraction:
                '/' => {
                    // Parse and save the numerator.
                    numerator = Some(self.parse_slice(init_idx, end_idx)?);
                    // Reset what's being read.
                    init_idx = idx + 1;
                }
                // If we reached the next node.
                '(' | '*' | ' ' | 'A'..='z' => {
                    // Parse the last value (either the denominator in case of a
                    // fraction, or the single number otherwise).
                    let last = self.parse_slice(init_idx, end_idx)?;
                    return Ok(Some(match numerator {
                        Some(num) => Edge::rational(num, last, end_idx)?,
                        None => Edge::int(last, end_idx)?,
                    }));
                }
                // Business as usual.
                '0'..='9' => {}
                // We found an unexpected symbol.
                _ => return Err(CdError::InvalidSymbol { pos: idx }),
            }
            end_idx = idx;
            self.next();
        }
    }
fn parse_edge ( & mut self ) -> CdResult < Option < Edge > > { let mut numerator = None ; let ( mut init_idx , c ) = self . peek ( ) . expect ( " " ) ; // If the next character is not numeric, this means this isn't an edge // at all, and we return None. if ! matches ! ( c '0' '9' ) { return Ok ( None ) ; } let mut end_idx = init_idx ; // We read through the diagram until we encounter something that // looks like the start of a node. loop { let ( idx , c ) = self . peek_or ( ) ? ; match c { // If we're dealing with a fraction: '/' => { // Parse and save the numerator. numerator = Some ( self . parse_slice ( init_idx , end_idx ) ? ) ; // Reset what's being read. init_idx = idx + 1 ; } // If we reached the next node. '(' | '*' | ' ' | 'A' ..= 'z' => { // Parse the last value (either the denominator in case of a // fraction, or the single number otherwise). let last = self . parse_slice ( init_idx , end_idx ) ? ; return Ok ( Some ( match numerator { Some ( num ) => Edge :: rational ( num , last , end_idx ) ? , None => Edge :: int ( last , end_idx ) ? , } ) ) ; } // Business as usual. '0' ..= '9' => { } // We found an unexpected symbol. _ => return Err ( CdError :: InvalidSymbol { pos : idx } ) , } end_idx = idx ; self . next ( ) ; } }
Parses the next edge in the Coxeter diagram.
Parses the next edge in the Coxeter diagram .
&mut self
&mut self
errors
This method will return a [`CdError::InvalidSymbol`] if it ever
encounters any unexpected symbol. Likewise, it will return a
[`CdError::InvalidEdge`] if the edge is something invalid like `1/0`.
This method will return a [ ` CdError :: InvalidSymbol ` ] if it ever encounters any unexpected symbol . Likewise it will return a [ ` CdError :: InvalidEdge ` ] if the edge is something invalid like ` 1 / 0 ` .