pub struct VersionSpecifier { /* private fields */ }Expand description
A version range such as >1.2.3, <=4!5.6.7-a8.post9.dev0 or == 4.1.*. Parse with
VersionSpecifier::from_str.
use std::str::FromStr;
use uv_pep440::{Version, VersionSpecifier};
let version = Version::from_str("1.19").unwrap();
let version_specifier = VersionSpecifier::from_str("== 1.*").unwrap();
assert!(version_specifier.contains(&version));PartialEq, Hash and Ord distinguish ~= specifiers by their
release segment count, since ~=10.1.0 (>=10.1.0, <10.2) and ~=10.1
(>=10.1, <11) match different version sets per PEP 440. For other
operators, trailing zeros are insignificant.
Implementations§
Source§impl VersionSpecifier
impl VersionSpecifier
Sourcepub fn from_pattern(
operator: Operator,
version_pattern: VersionPattern,
) -> Result<Self, VersionSpecifierBuildError>
pub fn from_pattern( operator: Operator, version_pattern: VersionPattern, ) -> Result<Self, VersionSpecifierBuildError>
Build from parts, validating that the operator is allowed with that version. The last
parameter indicates a trailing .*, to differentiate between 1.1.* and 1.1
Sourcepub fn from_version(
operator: Operator,
version: Version,
) -> Result<Self, VersionSpecifierBuildError>
pub fn from_version( operator: Operator, version: Version, ) -> Result<Self, VersionSpecifierBuildError>
Create a new version specifier from an operator and a version.
Sourcepub fn only_release(self) -> Self
pub fn only_release(self) -> Self
Remove all non-release parts of the version.
The marker decision diagram relies on the assumption that the negation of a marker tree is the complement of the marker space. However, pre-release versions violate this assumption.
For example, the marker python_full_version > '3.9' or python_full_version <= '3.9'
does not match python_full_version == 3.9.0a0 and so cannot simplify to true. However,
its negation, python_full_version > '3.9' and python_full_version <= '3.9', also does not
match 3.9.0a0 and simplifies to false, which violates the algebra decision diagrams
rely on. For this reason we ignore pre-release versions entirely when evaluating markers.
Note that python_version cannot take on pre-release values as it is truncated to just the
major and minor version segments. Thus using release-only specifiers is definitely necessary
for python_version to fully simplify any ranges, such as
python_version > '3.9' or python_version <= '3.9', which is always true for
python_version. For python_full_version however, this decision is a semantic change.
For Python versions, the major.minor is considered the API version, so unlike the rules
for package versions in PEP 440, we Python 3.9.0a0 is acceptable for >= "3.9".
Sourcepub fn only_minor_release(&self) -> Self
pub fn only_minor_release(&self) -> Self
Remove all parts of the version beyond the minor segment of the release.
Sourcepub fn equals_version(version: Version) -> Self
pub fn equals_version(version: Version) -> Self
==<version>
Sourcepub fn equals_star_version(version: Version) -> Self
pub fn equals_star_version(version: Version) -> Self
==<version>.*
Sourcepub fn not_equals_star_version(version: Version) -> Self
pub fn not_equals_star_version(version: Version) -> Self
!=<version>.*
Sourcepub fn not_equals_version(version: Version) -> Self
pub fn not_equals_version(version: Version) -> Self
!=<version>
Sourcepub fn greater_than_equal_version(version: Version) -> Self
pub fn greater_than_equal_version(version: Version) -> Self
>=<version>
Sourcepub fn greater_than_version(version: Version) -> Self
pub fn greater_than_version(version: Version) -> Self
><version>
Sourcepub fn less_than_equal_version(version: Version) -> Self
pub fn less_than_equal_version(version: Version) -> Self
<=<version>
Sourcepub fn less_than_version(version: Version) -> Self
pub fn less_than_version(version: Version) -> Self
<<version>
Sourcepub fn into_parts(self) -> (Operator, Version)
pub fn into_parts(self) -> (Operator, Version)
Get the operator and version parts of this specifier.
Sourcepub fn any_prerelease(&self) -> bool
pub fn any_prerelease(&self) -> bool
Whether the version marker includes a prerelease.
Sourcepub fn from_release_only_bounds(
bounds: (&Bound<Version>, &Bound<Version>),
) -> impl Iterator<Item = Self>
pub fn from_release_only_bounds( bounds: (&Bound<Version>, &Bound<Version>), ) -> impl Iterator<Item = Self>
Returns the version specifiers whose union represents the given range.
This function is not applicable to ranges involving pre-release versions.
Sourcepub fn from_lower_bound(bound: &Bound<Version>) -> Option<Self>
pub fn from_lower_bound(bound: &Bound<Version>) -> Option<Self>
Returns a version specifier representing the given lower bound.
Sourcepub fn from_upper_bound(bound: &Bound<Version>) -> Option<Self>
pub fn from_upper_bound(bound: &Bound<Version>) -> Option<Self>
Returns a version specifier representing the given upper bound.
Sourcepub fn contains(&self, version: &Version) -> bool
pub fn contains(&self, version: &Version) -> bool
Whether the given version satisfies the version range.
For example, >=1.19,<2.0 contains 1.21, but not 2.0.
See:
Sourcepub fn has_lower_bound(&self) -> bool
pub fn has_lower_bound(&self) -> bool
Whether this version specifier rejects versions below a lower cutoff.
Trait Implementations§
Source§impl Clone for VersionSpecifier
impl Clone for VersionSpecifier
Source§fn clone(&self) -> VersionSpecifier
fn clone(&self) -> VersionSpecifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more