Determines the highest semver version from a list of versions that satisfies all given version requirements.
-
Add the library to your
Cargo.toml:cargo add what-version-core
-
Call the
what_version()function with a list of versions and version requirements.let versions = vec![ Version::parse("1.0.0").unwrap(), Version::parse("1.1.0").unwrap(), Version::parse("1.2.3").unwrap(), Version::parse("1.6.0").unwrap(), Version::parse("2.0.0").unwrap(), ]; let requirements = vec![ VersionReq::parse(">=1.1.0").unwrap(), VersionReq::parse("<2.0.0").unwrap(), ] .into_iter() .collect::<HashSet<_>>(); match what_version(requirements, versions) { Ok(chosen_version) => println!("Chosen Version: {}", chosen_version), Err(_) => eprintln!("No valid version found"), }