pub struct Requirement {
pub kind: VersionKind,
pub op: Op,
pub scope: Option<CompactString>,
pub major: Option<u32>,
pub minor: Option<u32>,
pub patch: Option<u32>,
pub prerelease: Option<CompactString>,
}Expand description
A version requirement composed of a comparison operator and a full or partial version to match against. Build metadata is accepted when parsing, but is otherwise ignored.
Fields§
§kind: VersionKindThe kind of version.
op: OpThe comparison operator.
scope: Option<CompactString>An optional scope prefix, for example the “vendor” in vendor-1.2.
major: Option<u32>The major version number, or the year for calendar versions.
A None is either an omitted part or a wildcard.
minor: Option<u32>The minor version number, or the month for calendar versions.
A None is either an omitted part or a wildcard.
patch: Option<u32>The patch version number, or the day for calendar versions.
A None is either an omitted part or a wildcard.
prerelease: Option<CompactString>Optional pre-release identifier, for example the “alpha.1”
in >=1.2.3-alpha.1.
Implementations§
Source§impl Requirement
impl Requirement
Sourcepub fn parse<T>(value: T) -> Result<Requirement, SpecError>
pub fn parse<T>(value: T) -> Result<Requirement, SpecError>
Parses the provided value into a requirement.
Sourcepub fn matches_op(&self, version: &Version) -> bool
pub fn matches_op(&self, version: &Version) -> bool
Returns true if the provided version satisfies the requirement’s operator, without checking pre-release compatibility. A scoped requirement only matches versions with the same scope, while an unscoped requirement matches any scope.
Sourcepub fn matches_exact(&self, version: &Version) -> bool
pub fn matches_exact(&self, version: &Version) -> bool
Returns true if the provided version exactly matches all defined parts of this requirement, including the pre-release. Omitted parts match any value.
Sourcepub fn matches_greater(&self, version: &Version) -> bool
pub fn matches_greater(&self, version: &Version) -> bool
Returns true if the provided version is greater (>) than this
requirement. A partial requirement only matches versions beyond
the defined parts, for example >1 does not match 1.5.0.
Sourcepub fn matches_less(&self, version: &Version) -> bool
pub fn matches_less(&self, version: &Version) -> bool
Returns true if the provided version is less (<) than this requirement.
A partial requirement only matches versions below the defined parts.
Sourcepub fn matches_tilde(&self, version: &Version) -> bool
pub fn matches_tilde(&self, version: &Version) -> bool
Returns true for a patch-level (~) match: the defined major and
minor parts must be equal, while the remaining parts may drift higher.
Sourcepub fn matches_caret(&self, version: &Version) -> bool
pub fn matches_caret(&self, version: &Version) -> bool
Returns true for a compatible (^) match: parts may drift up to
the next major version, or the next minor or patch version when
the major or minor is 0.
Sourcepub fn matches_pre(&self, version: &Version) -> bool
pub fn matches_pre(&self, version: &Version) -> bool
Returns true if this requirement has a pre-release on the same version numbers as the provided version, allowing a pre-release version to be matched.
Trait Implementations§
Source§impl Clone for Requirement
impl Clone for Requirement
Source§fn clone(&self) -> Requirement
fn clone(&self) -> Requirement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Requirement
impl Debug for Requirement
Source§impl Default for Requirement
impl Default for Requirement
Source§fn default() -> Requirement
fn default() -> Requirement
Source§impl<'de> Deserialize<'de> for Requirement
impl<'de> Deserialize<'de> for Requirement
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Requirement, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Requirement, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Requirement
impl Display for Requirement
impl Eq for Requirement
Source§impl FormatsVersion for Requirement
impl FormatsVersion for Requirement
Source§fn to_formatted_string(&self, options: &FormatOptions) -> String
fn to_formatted_string(&self, options: &FormatOptions) -> String
Source§impl FromStr for Requirement
impl FromStr for Requirement
Source§impl Hash for Requirement
impl Hash for Requirement
Source§impl MatchesVersion for Requirement
impl MatchesVersion for Requirement
Source§impl Ord for Requirement
impl Ord for Requirement
Source§fn cmp(&self, other: &Requirement) -> Ordering
fn cmp(&self, other: &Requirement) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Requirement
impl PartialEq for Requirement
Source§impl PartialOrd for Requirement
impl PartialOrd for Requirement
Source§impl Serialize for Requirement
impl Serialize for Requirement
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Requirement
Auto Trait Implementations§
impl Freeze for Requirement
impl RefUnwindSafe for Requirement
impl Send for Requirement
impl Sync for Requirement
impl Unpin for Requirement
impl UnsafeUnpin for Requirement
impl UnwindSafe for Requirement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more