fn string_to_molecule<'s>(s: &'s str, atom_map: &mut HashMap<&'s str, Atom>) -> Result<Molecule> {
    let mut molecule = Molecule::new();
    let mut idx = 0;
    let mut bytes = s.bytes().peekable();
    while let Some(byte) = bytes.next() {
        if !byte.is_ascii_alphabetic() {
            return Err(Error::Input("non-alphabetic character in molecules"));
        }
        let atom_length = if byte == b'e' {
            if s != "e" {
                return Err(Error::Input(
                    "electron isn't allowed within a complex molecule",
                ));
            }
            1
        } else {
            if !byte.is_ascii_uppercase() {
                return Err(Error::Input(
                    "expected atom to start with an uppercase character",
                ));
            }
            let mut len = 1;
            while let Some(next_char) = bytes.peek().cloned() {
                if next_char.is_ascii_lowercase() {
                    len += 1;
                    bytes.next();
                    continue;
                }
                break;
            }
            len
        };
        let slice = &s[idx..idx + atom_length];
        idx += atom_length;
        let atom_map_len = atom_map.len();
        if atom_map_len == 256 {
            return Err(Error::Input("too many unique atoms"));
        }
        let atom = *atom_map.entry(slice).or_insert(atom_map_len as Atom);
        molecule.push(atom);
    }
    Ok(molecule)
}
/// Turns a string into a molecule, which is a more efficient in-memory representation
/// The maximum amount of unique atoms (including the electron) is 255.
Turns a string into a molecule, which is a more efficient in-memory representation
The maximum amount of unique atoms (including the electron) is 255.
Turns a string into a molecule which is a more efficient in - memory representation The maximum amount of unique atoms ( including the electron ) is 255 .
fn string_to_molecule<'s>(s: &'s str, atom_map: &mut HashMap<&'s str, Atom>) -> Result<Molecule> {
    let mut molecule = Molecule::new();
    let mut idx = 0;
    let mut bytes = s.bytes().peekable();
    while let Some(byte) = bytes.next() {
        if !byte.is_ascii_alphabetic() {
            return Err(Error::Input("non-alphabetic character in molecules"));
        }
        let atom_length = if byte == b'e' {
            if s != "e" {
                return Err(Error::Input(
                    "electron isn't allowed within a complex molecule",
                ));
            }
            1
        } else {
            if !byte.is_ascii_uppercase() {
                return Err(Error::Input(
                    "expected atom to start with an uppercase character",
                ));
            }
            let mut len = 1;
            while let Some(next_char) = bytes.peek().cloned() {
                if next_char.is_ascii_lowercase() {
                    len += 1;
                    bytes.next();
                    continue;
                }
                break;
            }
            len
        };
        let slice = &s[idx..idx + atom_length];
        idx += atom_length;
        let atom_map_len = atom_map.len();
        if atom_map_len == 256 {
            return Err(Error::Input("too many unique atoms"));
        }
        let atom = *atom_map.entry(slice).or_insert(atom_map_len as Atom);
        molecule.push(atom);
    }
    Ok(molecule)
}
fn string_to_molecule < ' s > ( s : & ' s str , atom_map : & mut HashMap < & ' s str , Atom > ) -> Result < Molecule > { let mut molecule = Molecule :: new ( ) ; let mut idx = 0 ; let mut bytes = s . bytes ( ) . peekable ( ) ; while let Some ( byte ) = bytes . next ( ) { if ! byte . is_ascii_alphabetic ( ) { return Err ( Error :: Input ( " " ) ) ; } let atom_length = if byte == b'e' { if s != " " { return Err ( Error :: Input ( " " , ) ) ; } 1 } else { if ! byte . is_ascii_uppercase ( ) { return Err ( Error :: Input ( " " , ) ) ; } let mut len = 1 ; while let Some ( next_char ) = bytes . peek ( ) . cloned ( ) { if next_char . is_ascii_lowercase ( ) { len += 1 ; bytes . next ( ) ; continue ; } break ; } len } ; let slice = & s [ idx .. idx + atom_length ] ; idx += atom_length ; let atom_map_len = atom_map . len ( ) ; if atom_map_len == 256 { return Err ( Error :: Input ( " " ) ) ; } let atom = * atom_map . entry ( slice ) . or_insert ( atom_map_len as Atom ) ; molecule . push ( atom ) ; } Ok ( molecule ) }
Turns a string into a molecule, which is a more efficient in-memory representation
The maximum amount of unique atoms (including the electron) is 255.
Turns a string into a molecule which is a more efficient in - memory representation The maximum amount of unique atoms ( including the electron ) is 255 .
s
&'s str
atom_map
&mut HashMap<&'s str, Atom>