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 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.