Struct semver::VersionReq 
source · pub struct VersionReq { /* private fields */ }Expand description
A VersionReq is a struct containing a list of predicates that can apply to ranges of version
numbers. Matching operations can then be done with the VersionReq against a particular
version to see if it satisfies some or all of the constraints.
Implementations§
source§impl VersionReq
 
impl VersionReq
sourcepub fn any() -> VersionReq
 
pub fn any() -> VersionReq
any() is a factory method which creates a VersionReq with no constraints. In other
words, any version will match against it.
Examples
use semver::VersionReq;
let anything = VersionReq::any();sourcepub fn parse(input: &str) -> Result<VersionReq, ReqParseError>
 
pub fn parse(input: &str) -> Result<VersionReq, ReqParseError>
parse() is the main constructor of a VersionReq. It takes a string like "^1.2.3"
and turns it into a VersionReq that matches that particular constraint.
A Result is returned which contains a ReqParseError if there was a problem parsing the
VersionReq.
Examples
use semver::VersionReq;
let version = VersionReq::parse("=1.2.3");
let version = VersionReq::parse(">1.2.3");
let version = VersionReq::parse("<1.2.3");
let version = VersionReq::parse("~1.2.3");
let version = VersionReq::parse("^1.2.3");
let version = VersionReq::parse("1.2.3"); // synonym for ^1.2.3
let version = VersionReq::parse("<=1.2.3");
let version = VersionReq::parse(">=1.2.3");This example demonstrates error handling, and will panic.
use semver::VersionReq;
let version = match VersionReq::parse("not a version") {
    Ok(version) => version,
    Err(e) => panic!("There was a problem parsing: {}", e),
}
sourcepub fn exact(version: &Version) -> VersionReq
 
pub fn exact(version: &Version) -> VersionReq
exact() is a factory method which creates a VersionReq with one exact constraint.
Examples
use semver::VersionReq;
use semver::Version;
let version = Version { major: 1, minor: 1, patch: 1, pre: vec![], build: vec![] };
let exact = VersionReq::exact(&version);sourcepub fn matches(&self, version: &Version) -> bool
 
pub fn matches(&self, version: &Version) -> bool
matches() matches a given Version against this VersionReq.
Examples
use semver::VersionReq;
use semver::Version;
let version = Version { major: 1, minor: 1, patch: 1, pre: vec![], build: vec![] };
let exact = VersionReq::exact(&version);
assert!(exact.matches(&version));Trait Implementations§
source§impl Clone for VersionReq
 
impl Clone for VersionReq
source§fn clone(&self) -> VersionReq
 
fn clone(&self) -> VersionReq
1.0.0 · source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for VersionReq
 
impl Debug for VersionReq
source§impl Display for VersionReq
 
impl Display for VersionReq
source§impl From<VersionReq> for VersionReq
 
impl From<VersionReq> for VersionReq
source§fn from(other: VersionReq) -> VersionReq
 
fn from(other: VersionReq) -> VersionReq
source§impl FromStr for VersionReq
 
impl FromStr for VersionReq
§type Err = ReqParseError
 
type Err = ReqParseError
source§fn from_str(s: &str) -> Result<VersionReq, ReqParseError>
 
fn from_str(s: &str) -> Result<VersionReq, ReqParseError>
s to return a value of this type. Read moresource§impl Hash for VersionReq
 
impl Hash for VersionReq
source§impl Ord for VersionReq
 
impl Ord for VersionReq
source§fn cmp(&self, other: &VersionReq) -> Ordering
 
fn cmp(&self, other: &VersionReq) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
    Self: Sized,
 
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<VersionReq> for VersionReq
 
impl PartialEq<VersionReq> for VersionReq
source§fn eq(&self, other: &VersionReq) -> bool
 
fn eq(&self, other: &VersionReq) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<VersionReq> for VersionReq
 
impl PartialOrd<VersionReq> for VersionReq
source§fn partial_cmp(&self, other: &VersionReq) -> Option<Ordering>
 
fn partial_cmp(&self, other: &VersionReq) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
 
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more