pub fn check(self) -> Result<Nfa<Sanitary>, NfaError> {
        let Nfa {
            start,
            final_states,
            alphabet,
            nodes,
            ..
        } = self;

        // ensure that the start state is a valid state
        if !nodes.contains_key(&start) {
            return Err(NfaError::UnknownState(start));
        }

        // ensure that all final states are listed as actual states
        if let Some(unknown_state) = final_states
            .iter()
            .find(|&state| !nodes.contains_key(state))
        {
            return Err(NfaError::UnknownState(unknown_state.to_owned()));
        }

        // ensure that all state transitions are on valid symbols
        if let Some((unknown_symbol, _)) = nodes
            .iter()
            .filter_map(|(_, maps)| {
                maps.iter().find(|&(symbol, _)| !alphabet.contains(symbol))
            })
            .next()
        {
            return Err(NfaError::UnknownSymbol(unknown_symbol.to_owned()));
        }

        // ensure that all state transitions are to valid states
        if let Some(unknown_state) = nodes
            .iter()
            .filter_map(|(_, maps)| {
                maps.iter()
                    .filter_map(|(_, states)| {
                        states.iter().find(|&state| !nodes.contains_key(state))
                    })
                    .next()
            })
            .next()
        {
            return Err(NfaError::UnknownState(unknown_state.to_owned()));
        }

        if let Some(invalid_state) = nodes.iter().map(|(state, _)| state).find(|&state| {
            /*state.contains("+") || state.contains("|") || */ state.is_empty()
        }) {
            return Err(NfaError::InvalidStateName(invalid_state.to_owned()));
        }

        Ok(Nfa {
            _sanitized: Sanitary,
            start,
            final_states,
            alphabet,
            nodes,
        })
    }
/// Ensures that the NFA is valid, and that relevant invariants within the structure hold.
Ensures that the NFA is valid, and that relevant invariants within the structure hold.
Ensures that the NFA is valid and that relevant invariants within the structure hold .
pub fn check(self) -> Result<Nfa<Sanitary>, NfaError> {
        let Nfa {
            start,
            final_states,
            alphabet,
            nodes,
            ..
        } = self;
        // ensure that the start state is a valid state
        if !nodes.contains_key(&start) {
            return Err(NfaError::UnknownState(start));
        }
        // ensure that all final states are listed as actual states
        if let Some(unknown_state) = final_states
            .iter()
            .find(|&state| !nodes.contains_key(state))
        {
            return Err(NfaError::UnknownState(unknown_state.to_owned()));
        }
        // ensure that all state transitions are on valid symbols
        if let Some((unknown_symbol, _)) = nodes
            .iter()
            .filter_map(|(_, maps)| {
                maps.iter().find(|&(symbol, _)| !alphabet.contains(symbol))
            })
            .next()
        {
            return Err(NfaError::UnknownSymbol(unknown_symbol.to_owned()));
        }
        // ensure that all state transitions are to valid states
        if let Some(unknown_state) = nodes
            .iter()
            .filter_map(|(_, maps)| {
                maps.iter()
                    .filter_map(|(_, states)| {
                        states.iter().find(|&state| !nodes.contains_key(state))
                    })
                    .next()
            })
            .next()
        {
            return Err(NfaError::UnknownState(unknown_state.to_owned()));
        }
        if let Some(invalid_state) = nodes.iter().map(|(state, _)| state).find(|&state| {
            /*state.contains("+") || state.contains("|") || */ state.is_empty()
        }) {
            return Err(NfaError::InvalidStateName(invalid_state.to_owned()));
        }
        Ok(Nfa {
            _sanitized: Sanitary,
            start,
            final_states,
            alphabet,
            nodes,
        })
    }
pub fn check ( self ) -> Result < Nfa < Sanitary > , NfaError > { let Nfa { start , final_states , alphabet , nodes , .. } = self ; // ensure that the start state is a valid state if ! nodes . contains_key ( & start ) { return Err ( NfaError :: UnknownState ( start ) ) ; } // ensure that all final states are listed as actual states if let Some ( unknown_state ) = final_states . iter ( ) . find ( | & state | ! nodes . contains_key ( state ) ) { return Err ( NfaError :: UnknownState ( unknown_state . to_owned ( ) ) ) ; } // ensure that all state transitions are on valid symbols if let Some ( ( unknown_symbol , _ ) ) = nodes . iter ( ) . filter_map ( | ( _ , maps ) | { maps . iter ( ) . find ( | & ( symbol , _ ) | ! alphabet . contains ( symbol ) ) } ) . next ( ) { return Err ( NfaError :: UnknownSymbol ( unknown_symbol . to_owned ( ) ) ) ; } // ensure that all state transitions are to valid states if let Some ( unknown_state ) = nodes . iter ( ) . filter_map ( | ( _ , maps ) | { maps . iter ( ) . filter_map ( | ( _ , states ) | { states . iter ( ) . find ( | & state | ! nodes . contains_key ( state ) ) } ) . next ( ) } ) . next ( ) { return Err ( NfaError :: UnknownState ( unknown_state . to_owned ( ) ) ) ; } if let Some ( invalid_state ) = nodes . iter ( ) . map ( | ( state , _ ) | state ) . find ( | & state | { /*state.contains("+") || state.contains("|") || */ state . is_empty ( ) } ) { return Err ( NfaError :: InvalidStateName ( invalid_state . to_owned ( ) ) ) ; } Ok ( Nfa { _sanitized : Sanitary , start , final_states , alphabet , nodes , } ) }
Ensures that the NFA is valid, and that relevant invariants within the structure hold.
Ensures that the NFA is valid and that relevant invariants within the structure hold .
self
self