Struct pep440_rs::VersionSpecifier
source · pub struct VersionSpecifier { /* private fields */ }
Expand description
A version range such 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 pep440_rs::{Version, VersionSpecifier};
let version = Version::from_str("1.19").unwrap();
let version_specifier = VersionSpecifier::from_str("== 1.*").unwrap();
assert!(version_specifier.contains(&version));
Implementations§
source§impl VersionSpecifier
impl VersionSpecifier
sourcepub fn new(
operator: Operator,
version_pattern: VersionPattern
) -> Result<Self, VersionSpecifierBuildError>
pub fn new( 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 equals_version(version: Version) -> Self
pub fn equals_version(version: Version) -> Self
==<version>
sourcepub fn any_prerelease(&self) -> bool
pub fn any_prerelease(&self) -> bool
Whether the version marker includes a prerelease.
sourcepub fn contains(&self, version: &Version) -> bool
pub fn contains(&self, version: &Version) -> bool
Whether the given version satisfies the version range
e.g. >=1.19,<2.0
and 1.21
-> true
https://peps.python.org/pep-0440/#version-specifiers
Unlike pypa/packaging
, prereleases are included by default
I’m utterly non-confident in the description in PEP 440 and apparently even pip got some of that wrong, e.g. https://github.com/pypa/pip/issues/9121 and https://github.com/pypa/pip/issues/5503, and also i’m not sure if it produces the correct behaviour from a user perspective
This implementation is as close as possible to https://github.com/pypa/packaging/blob/e184feef1a28a5c574ec41f5c263a3a573861f5a/packaging/specifiers.py#L362-L496
Trait Implementations§
source§impl Clone for VersionSpecifier
impl Clone for VersionSpecifier
source§fn clone(&self) -> VersionSpecifier
fn clone(&self) -> VersionSpecifier
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for VersionSpecifier
impl Debug for VersionSpecifier
source§impl Display for VersionSpecifier
impl Display for VersionSpecifier
source§impl From<VersionSpecifier> for VersionSpecifiers
impl From<VersionSpecifier> for VersionSpecifiers
source§fn from(specifier: VersionSpecifier) -> Self
fn from(specifier: VersionSpecifier) -> Self
source§impl FromIterator<VersionSpecifier> for VersionSpecifiers
impl FromIterator<VersionSpecifier> for VersionSpecifiers
source§fn from_iter<T: IntoIterator<Item = VersionSpecifier>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = VersionSpecifier>>(iter: T) -> Self
source§impl FromStr for VersionSpecifier
impl FromStr for VersionSpecifier
source§impl Hash for VersionSpecifier
impl Hash for VersionSpecifier
source§impl PartialEq for VersionSpecifier
impl PartialEq for VersionSpecifier
source§fn eq(&self, other: &VersionSpecifier) -> bool
fn eq(&self, other: &VersionSpecifier) -> bool
self
and other
values to be equal, and is used
by ==
.