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
sourceimpl 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
.
ReqParseError
: enum.ReqParseError.html
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),
};
Errors
Returns an error variant if the input could not be parsed as a semver requirement.
Examples of common error causes are as follows:
\0
- an invalid version requirement is used.>= >= 1.2.3
- multiple operations are used. Only use one.>== 1.2.3
- an invalid operation is used.a.0.0
- version components are not numeric.1.2.3-
- an invalid identifier is present.>=
- major version was not specified. At least a major version is required.0.2*
- deprecated requirement syntax. Equivalent would be0.2.*
.
You may also encounter an UnimplementedVersionRequirement
error, which indicates that a
given requirement syntax is not yet implemented in this crate.
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
.
Version
: struct.Version.html
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));
sourcepub fn is_exact(&self) -> bool
pub fn is_exact(&self) -> bool
is_exact()
returns true
if there is exactly one version which could match this
VersionReq
. If false
is returned, it is possible that there may still only be exactly
one version which could match this VersionReq
. This function is intended do allow
short-circuiting more complex logic where being able to handle only the possibility of a
single exact version may be cheaper.
Examples
use semver::ReqParseError;
use semver::VersionReq;
fn use_is_exact() -> Result<(), ReqParseError> {
assert!(VersionReq::parse("=1.0.0")?.is_exact());
assert!(!VersionReq::parse("=1.0")?.is_exact());
assert!(!VersionReq::parse(">=1.0.0")?.is_exact());
Ok(())
}
use_is_exact().unwrap();
Trait Implementations
sourceimpl Clone for VersionReq
impl Clone for VersionReq
sourcefn clone(&self) -> VersionReq
fn clone(&self) -> VersionReq
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for VersionReq
impl Debug for VersionReq
sourceimpl<'de> Deserialize<'de> for VersionReq
impl<'de> Deserialize<'de> for VersionReq
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for VersionReq
impl Display for VersionReq
sourceimpl From<VersionReq> for VersionReq
impl From<VersionReq> for VersionReq
sourcefn from(other: VersionReq) -> VersionReq
fn from(other: VersionReq) -> VersionReq
Performs the conversion.
sourceimpl FromStr for VersionReq
impl FromStr for VersionReq
type Err = ReqParseError
type Err = ReqParseError
The associated error which can be returned from parsing.
sourcefn from_str(s: &str) -> Result<VersionReq, ReqParseError>
fn from_str(s: &str) -> Result<VersionReq, ReqParseError>
Parses a string s
to return a value of this type. Read more
sourceimpl Hash for VersionReq
impl Hash for VersionReq
sourceimpl Ord for VersionReq
impl Ord for VersionReq
sourceimpl PartialEq<VersionReq> for VersionReq
impl PartialEq<VersionReq> for VersionReq
sourcefn eq(&self, other: &VersionReq) -> bool
fn eq(&self, other: &VersionReq) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &VersionReq) -> bool
fn ne(&self, other: &VersionReq) -> bool
This method tests for !=
.
sourceimpl PartialOrd<VersionReq> for VersionReq
impl PartialOrd<VersionReq> for VersionReq
sourcefn partial_cmp(&self, other: &VersionReq) -> Option<Ordering>
fn partial_cmp(&self, other: &VersionReq) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Serialize for VersionReq
impl Serialize for VersionReq
impl Eq for VersionReq
impl StructuralEq for VersionReq
impl StructuralPartialEq for VersionReq
Auto Trait Implementations
impl RefUnwindSafe for VersionReq
impl Send for VersionReq
impl Sync for VersionReq
impl Unpin for VersionReq
impl UnwindSafe for VersionReq
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more