pub struct Range(/* private fields */);Expand description
Node-style semver range.
These ranges map mostly 1:1 to semver’s except for some internal representation details that allow some more interesting set-level operations.
For details on supported syntax, see https://github.com/npm/node-semver#advanced-range-syntax
Implementations§
Source§impl Range
impl Range
Sourcepub fn parse<S: AsRef<str>>(input: S) -> Result<Self, SemverError>
pub fn parse<S: AsRef<str>>(input: S) -> Result<Self, SemverError>
Parse a range from a string.
Sourcepub fn satisfies(&self, version: &Version) -> bool
pub fn satisfies(&self, version: &Version) -> bool
Returns true if version is satisfied by this range.
Sourcepub fn satisfies_with_prerelease(
&self,
version: &Version,
include_prerelease: bool,
) -> bool
pub fn satisfies_with_prerelease( &self, version: &Version, include_prerelease: bool, ) -> bool
Returns true if version is satisfied by this range.
This behaves like Range::satisfies, but will also consider pre-release versions even if the range itself does not specify a matching pre-release.
Sourcepub fn allows_all(&self, other: &Range) -> bool
pub fn allows_all(&self, other: &Range) -> bool
Returns true if other is a strict superset of this range.
Sourcepub fn allows_any(&self, other: &Range) -> bool
pub fn allows_any(&self, other: &Range) -> bool
Returns true if other has overlap with this range.
Sourcepub fn intersect(&self, other: &Self) -> Option<Self>
pub fn intersect(&self, other: &Self) -> Option<Self>
Returns a new range that is the set-intersection between this range and other.
Sourcepub fn difference(&self, other: &Self) -> Option<Self>
pub fn difference(&self, other: &Self) -> Option<Self>
Returns a new range that is the set-difference between this range and other.
Sourcepub fn max_satisfying<'v>(&self, versions: &'v [Version]) -> Option<&'v Version>
pub fn max_satisfying<'v>(&self, versions: &'v [Version]) -> Option<&'v Version>
Return the highest Version in the list that satisfies the range,
or None if none of them do.
use nodejs_semver::{Range, Version};
fn main() {
let versions: Vec<_> = vec!["1.2.3", "1.2.4", "1.2.5", "1.2.6"]
.iter()
.map(|s| Version::parse(s).unwrap())
.collect();
let range = Range::parse("~1.2.3").unwrap();
let result = range.max_satisfying(&versions);
assert_eq!(result, Some(&Version::parse("1.2.6").unwrap()));
}Sourcepub fn min_satisfying<'v>(&self, versions: &'v [Version]) -> Option<&'v Version>
pub fn min_satisfying<'v>(&self, versions: &'v [Version]) -> Option<&'v Version>
Return the lowest Version in the list that satisfies the range,
or None if none of them do.
use nodejs_semver::{Range, Version};
fn main() {
let versions: Vec<_> = vec!["1.2.3", "1.2.4", "1.2.5", "1.2.6"]
.iter()
.map(|s| Version::parse(s).unwrap())
.collect();
let range = Range::parse("~1.2.3").unwrap();
let result = range.min_satisfying(&versions);
assert_eq!(result, Some(&Version::parse("1.2.3").unwrap()));
}Sourcepub fn min_version(&self) -> Option<Version>
pub fn min_version(&self) -> Option<Version>
Return the lowest Version that can possibly match the given range.
Sourcepub fn outside(
&self,
version: &Version,
direction: OutsideDirection,
include_prerelease: bool,
) -> Result<bool, RangeError>
pub fn outside( &self, version: &Version, direction: OutsideDirection, include_prerelease: bool, ) -> Result<bool, RangeError>
Return Ok(true) if the Version sits entirely outside this range in
the specified direction.
direction mirrors the JavaScript implementation’s “hi/lo” flag:
OutsideDirection::Higher checks whether the version is greater than
the range, while OutsideDirection::Lower checks whether it is lower.
Set include_prerelease to true to treat prerelease versions as
satisfiable even when the range does not explicitly mention them.
§Errors
Returns RangeError::MissingComparatorBounds if the range does not
expose enough comparator information to perform the comparison.