pub(crate) fn from_str(version_number_str: &'py str) -> Result<Self, &str> {
        fn split_and_parse_number(version_part: &str) -> (u8, Option<&str>) {
            match version_part.find(|c: char| !c.is_ascii_digit()) {
                None => (version_part.parse().unwrap(), None),
                Some(version_part_suffix_start) => {
                    let (version_part, version_part_suffix) =
                        version_part.split_at(version_part_suffix_start);
                    (version_part.parse().unwrap(), Some(version_part_suffix))
                }
            }
        }

        let mut parts = version_number_str.split('.');
        let major_str = parts.next().ok_or("Python major version missing")?;
        let minor_str = parts.next().ok_or("Python minor version missing")?;
        let patch_str = parts.next();
        if parts.next().is_some() {
            return Err("Python version string has too many parts");
        };

        let major = major_str
            .parse()
            .map_err(|_| "Python major version not an integer")?;
        let (minor, suffix) = split_and_parse_number(minor_str);
        if suffix.is_some() {
            assert!(patch_str.is_none());
            return Ok(PythonVersionInfo {
                major,
                minor,
                patch: 0,
                suffix,
            });
        }

        let (patch, suffix) = patch_str.map(split_and_parse_number).unwrap_or_default();
        Ok(PythonVersionInfo {
            major,
            minor,
            patch,
            suffix,
        })
    }
/// Parses a hard-coded Python interpreter version string (e.g. 3.9.0a4+).
Parses a hard-coded Python interpreter version string .
Parses a hard - coded Python interpreter version string .
pub(crate) fn from_str(version_number_str: &'py str) -> Result<Self, &str> {
        fn split_and_parse_number(version_part: &str) -> (u8, Option<&str>) {
            match version_part.find(|c: char| !c.is_ascii_digit()) {
                None => (version_part.parse().unwrap(), None),
                Some(version_part_suffix_start) => {
                    let (version_part, version_part_suffix) =
                        version_part.split_at(version_part_suffix_start);
                    (version_part.parse().unwrap(), Some(version_part_suffix))
                }
            }
        }
        let mut parts = version_number_str.split('.');
        let major_str = parts.next().ok_or("Python major version missing")?;
        let minor_str = parts.next().ok_or("Python minor version missing")?;
        let patch_str = parts.next();
        if parts.next().is_some() {
            return Err("Python version string has too many parts");
        };
        let major = major_str
            .parse()
            .map_err(|_| "Python major version not an integer")?;
        let (minor, suffix) = split_and_parse_number(minor_str);
        if suffix.is_some() {
            assert!(patch_str.is_none());
            return Ok(PythonVersionInfo {
                major,
                minor,
                patch: 0,
                suffix,
            });
        }
        let (patch, suffix) = patch_str.map(split_and_parse_number).unwrap_or_default();
        Ok(PythonVersionInfo {
            major,
            minor,
            patch,
            suffix,
        })
    }
pub ( crate ) fn from_str ( version_number_str : & ' py str ) -> Result < Self , & str > { fn split_and_parse_number ( version_part : & str ) -> ( u8 , Option < & str > ) { match version_part . find ( | c : char | ! c . is_ascii_digit ( ) ) { None => ( version_part . parse ( ) . unwrap ( ) , None ) , Some ( version_part_suffix_start ) => { let ( version_part , version_part_suffix ) = version_part . split_at ( version_part_suffix_start ) ; ( version_part . parse ( ) . unwrap ( ) , Some ( version_part_suffix ) ) } } } let mut parts = version_number_str . split ( '.' ) ; let major_str = parts . next ( ) . ok_or ( " " ) ? ; let minor_str = parts . next ( ) . ok_or ( " " ) ? ; let patch_str = parts . next ( ) ; if parts . next ( ) . is_some ( ) { return Err ( " " ) ; } ; let major = major_str . parse ( ) . map_err ( | _ | " " ) ? ; let ( minor , suffix ) = split_and_parse_number ( minor_str ) ; if suffix . is_some ( ) { assert ! ( patch_str is_none ( ) ) ; return Ok ( PythonVersionInfo { major , minor , patch : 0 , suffix , } ) ; } let ( patch , suffix ) = patch_str . map ( split_and_parse_number ) . unwrap_or_default ( ) ; Ok ( PythonVersionInfo { major , minor , patch , suffix , } ) }
Parses a hard-coded Python interpreter version string (e.g.
Parses a hard - coded Python interpreter version string ( e . g .
version_number_str
&'py str
version_number_str
&'py str