pub struct Range {
pub predicates: Vec<Predicate>,
}
Expand description
A Range
is a struct containing a list of predicates that can apply to ranges of version
numbers. Matching operations can then be done with the Range
against a particular
version to see if it satisfies some or all of the constraints.
Fields§
§predicates: Vec<Predicate>
Implementations§
Source§impl Range
impl Range
Sourcepub fn any() -> Range
pub fn any() -> Range
any()
is a factory method which creates a Range
with no constraints. In other
words, any version will match against it.
§Examples
use reproto_semver::Range;
let anything = Range::any();
Sourcepub fn parse(input: &str) -> Result<Range, Error<'_>>
pub fn parse(input: &str) -> Result<Range, Error<'_>>
parse()
is the main constructor of a Range
. It takes a string like "^1.2.3"
and turns it into a Range
that matches that particular constraint.
A Result
is returned which contains a Error
if there was a problem parsing the Range
.
§Examples
use reproto_semver::Range;
let version = Range::parse("=1.2.3");
let version = Range::parse(">1.2.3");
let version = Range::parse("<1.2.3");
let version = Range::parse("~1.2.3");
let version = Range::parse("^1.2.3");
let version = Range::parse("1.2.3"); // synonym for ^1.2.3
let version = Range::parse("<=1.2.3");
let version = Range::parse(">=1.2.3");
This example demonstrates error handling, and will panic.
use reproto_semver::Range;
let version = match Range::parse("not a version") {
Ok(version) => version,
Err(e) => panic!("There was a problem parsing: {}", e),
}
Sourcepub fn exact(version: &Version) -> Range
pub fn exact(version: &Version) -> Range
exact()
is a factory method which creates a Range
with one exact constraint.
§Examples
use reproto_semver::Range;
use reproto_semver::Version;
let version = Version { major: 1, minor: 1, patch: 1, pre: vec![], build: vec![] };
let exact = Range::exact(&version);
Sourcepub fn matches(&self, version: &Version) -> bool
pub fn matches(&self, version: &Version) -> bool
matches()
matches a given Version
against this Range
.
§Examples
use reproto_semver::Range;
use reproto_semver::Version;
let version = Version { major: 1, minor: 1, patch: 1, pre: vec![], build: vec![] };
let exact = Range::exact(&version);
assert!(exact.matches(&version));
Sourcepub fn matches_any(&self) -> bool
pub fn matches_any(&self) -> bool
Check if range matches any.