fn version_from_cargo_feature() -> Result<PythonVersion, String> {
    let re = Regex::new(r"CARGO_FEATURE_BUILD_PYTHON_(\d+)_(\d+)(_(.+))?").unwrap();
    let mut vars = env::vars().collect::<Vec<_>>();
    vars.sort_by(|a, b| b.cmp(a));
    for (key, _) in vars {
        match re.captures(&key) {
            Some(cap) => {
                return Ok(PythonVersion {
                    major: cap.get(1).unwrap().as_str().parse().unwrap(),
                    minor: cap.get(2).unwrap().as_str().parse().unwrap(),
                    patch: match cap.get(4) {
                        Some(s) => Some(String::from(s.as_str())),
                        None => None,
                    },
                })
            }
            None => (),
        }
    }
    Err("Python version feature was not found.".to_owned())
}
/// Function copied and modified from rust-python:
/// https://github.com/dgrunwald/rust-cpython/blob/master/python3-sys/build.rs
///
/// Determine the python version we're supposed to be building
/// from the features passed via the environment.
///


Determine the python version we're supposed to be building
from the features passed via the environment.
Determine the python version we ' re supposed to be building from the features passed via the environment .
fn version_from_cargo_feature() -> Result<PythonVersion, String> {
    let re = Regex::new(r"CARGO_FEATURE_BUILD_PYTHON_(\d+)_(\d+)(_(.+))?").unwrap();
    let mut vars = env::vars().collect::<Vec<_>>();
    vars.sort_by(|a, b| b.cmp(a));
    for (key, _) in vars {
        match re.captures(&key) {
            Some(cap) => {
                return Ok(PythonVersion {
                    major: cap.get(1).unwrap().as_str().parse().unwrap(),
                    minor: cap.get(2).unwrap().as_str().parse().unwrap(),
                    patch: match cap.get(4) {
                        Some(s) => Some(String::from(s.as_str())),
                        None => None,
                    },
                })
            }
            None => (),
        }
    }
    Err("Python version feature was not found.".to_owned())
}
fn version_from_cargo_feature ( ) -> Result < PythonVersion , String > { let re = Regex :: new ( r"CARGO_FEATURE_BUILD_PYTHON_(\d+)_(\d+)(_(.+))?" ) . unwrap ( ) ; let mut vars = env :: vars ( ) . collect :: < Vec < _ > > ( ) ; vars . sort_by ( | a , b | b . cmp ( a ) ) ; for ( key , _ ) in vars { match re . captures ( & key ) { Some ( cap ) => { return Ok ( PythonVersion { major : cap . get ( 1 ) . unwrap ( ) . as_str ( ) . parse ( ) . unwrap ( ) , minor : cap . get ( 2 ) . unwrap ( ) . as_str ( ) . parse ( ) . unwrap ( ) , patch : match cap . get ( 4 ) { Some ( s ) => Some ( String :: from ( s . as_str ( ) ) ) , None => None , } , } ) } None => ( ) , } } Err ( " " . to_owned ( ) ) }
Function copied and modified from rust-python:
https://github.com/dgrunwald/rust-cpython/blob/master/python3-sys/build.rs
Function copied and modified from rust - python : https : // github . com / dgrunwald / rust - cpython / blob / master / python3 - sys / build . rs