fn new_rec(
        prefix: &str,
        entry: &Vec<Vec<&str>>,
        index: usize,
    ) -> Result<NumeralSystem, BibiError> {
        let mut len_digit;
        let mut digits: IndexMap<String, u32> = IndexMap::new();
        let mut revdigits: IndexMap<u32, String> = IndexMap::new();

        let first_entry = &entry[index];

        match first_entry.first() {
            None => return Err(BibiError::BadNumeralSystem),
            Some(digit) => len_digit = digit.len(),
        }

        if len_digit == 0 {
            return Err(BibiError::BadNumeralSystem);
        }

        let mut sub_num_sys = None;
        if index < entry.len() - 1 {
            sub_num_sys = Some(NumeralSystem::new_rec(prefix, entry, index + 1)?);
        }

        let mut cpt: u32 = 0;
        for digit in first_entry {
            if digit.len() != len_digit {
                return Err(BibiError::BadNumeralSystem);
            }
            if let Some(num) = sub_num_sys {
                for digit2 in num.digits.keys() {
                    digits
                        .entry(String::from(*digit) + &String::from(&digit2[..]))
                        .or_insert(cpt);
                    revdigits.insert(cpt, String::from(*digit) + &String::from(&digit2[..]));
                    cpt = cpt + 1;
                }
                sub_num_sys = Some(num);
            } else {
                digits.entry(String::from(*digit)).or_insert(cpt);
                revdigits.insert(cpt, String::from(*digit));
                cpt = cpt + 1;
            }
        }

        // check for unique digits
        if cpt != digits.len() as u32 {
            return Err(BibiError::BadNumeralSystem);
        }

        if let Some(num) = sub_num_sys {
            len_digit = len_digit + num.len_digit;
        }

        Ok(NumeralSystem {
            prefix: String::from(prefix),
            len_digit: len_digit,
            digits: digits,
            revdigits: revdigits,
        })
    }
// internal method to build system from vec of vec
internal method to build system from vec of vec
internal method to build system from vec of vec
fn new_rec(
        prefix: &str,
        entry: &Vec<Vec<&str>>,
        index: usize,
    ) -> Result<NumeralSystem, BibiError> {
        let mut len_digit;
        let mut digits: IndexMap<String, u32> = IndexMap::new();
        let mut revdigits: IndexMap<u32, String> = IndexMap::new();
        let first_entry = &entry[index];
        match first_entry.first() {
            None => return Err(BibiError::BadNumeralSystem),
            Some(digit) => len_digit = digit.len(),
        }
        if len_digit == 0 {
            return Err(BibiError::BadNumeralSystem);
        }
        let mut sub_num_sys = None;
        if index < entry.len() - 1 {
            sub_num_sys = Some(NumeralSystem::new_rec(prefix, entry, index + 1)?);
        }
        let mut cpt: u32 = 0;
        for digit in first_entry {
            if digit.len() != len_digit {
                return Err(BibiError::BadNumeralSystem);
            }
            if let Some(num) = sub_num_sys {
                for digit2 in num.digits.keys() {
                    digits
                        .entry(String::from(*digit) + &String::from(&digit2[..]))
                        .or_insert(cpt);
                    revdigits.insert(cpt, String::from(*digit) + &String::from(&digit2[..]));
                    cpt = cpt + 1;
                }
                sub_num_sys = Some(num);
            } else {
                digits.entry(String::from(*digit)).or_insert(cpt);
                revdigits.insert(cpt, String::from(*digit));
                cpt = cpt + 1;
            }
        }
        // check for unique digits
        if cpt != digits.len() as u32 {
            return Err(BibiError::BadNumeralSystem);
        }
        if let Some(num) = sub_num_sys {
            len_digit = len_digit + num.len_digit;
        }
        Ok(NumeralSystem {
            prefix: String::from(prefix),
            len_digit: len_digit,
            digits: digits,
            revdigits: revdigits,
        })
    }
fn new_rec ( prefix : & str , entry : & Vec < Vec < & str > > , index : usize , ) -> Result < NumeralSystem , BibiError > { let mut len_digit ; let mut digits : IndexMap < String , u32 > = IndexMap :: new ( ) ; let mut revdigits : IndexMap < u32 , String > = IndexMap :: new ( ) ; let first_entry = & entry [ index ] ; match first_entry . first ( ) { None => return Err ( BibiError :: BadNumeralSystem ) , Some ( digit ) => len_digit = digit . len ( ) , } if len_digit == 0 { return Err ( BibiError :: BadNumeralSystem ) ; } let mut sub_num_sys = None ; if index < entry . len ( ) - 1 { sub_num_sys = Some ( NumeralSystem :: new_rec ( prefix , entry , index + 1 ) ? ) ; } let mut cpt : u32 = 0 ; for digit in first_entry { if digit . len ( ) != len_digit { return Err ( BibiError :: BadNumeralSystem ) ; } if let Some ( num ) = sub_num_sys { for digit2 in num . digits . keys ( ) { digits . entry ( String :: from ( * digit ) + & String :: from ( & digit2 [ .. ] ) ) . or_insert ( cpt ) ; revdigits . insert ( cpt , String :: from ( * digit ) + & String :: from ( & digit2 [ .. ] ) ) ; cpt = cpt + 1 ; } sub_num_sys = Some ( num ) ; } else { digits . entry ( String :: from ( * digit ) ) . or_insert ( cpt ) ; revdigits . insert ( cpt , String :: from ( * digit ) ) ; cpt = cpt + 1 ; } } // check for unique digits if cpt != digits . len ( ) as u32 { return Err ( BibiError :: BadNumeralSystem ) ; } if let Some ( num ) = sub_num_sys { len_digit = len_digit + num . len_digit ; } Ok ( NumeralSystem { prefix : String :: from ( prefix ) , len_digit : len_digit , digits : digits , revdigits : revdigits , } ) }
internal method to build system from vec of vec
internal method to build system from vec of vec
prefix
&str
entry
&Vec<Vec<&str>>
index
usize
prefix
&str
entry
&Vec<Vec<&str>>
index
usize