pub struct VersionRequirement {
pub comparison: VersionComparison,
pub version: Version,
}
Expand description
A version requirement, e.g. for a dependency package.
It consists of a target version and a comparison function. A version requirement of >=1.5
has
a target version of 1.5
and a comparison function of VersionComparison::GreaterOrEqual
.
See alpm-comparison for details on the format.
§Examples
use std::str::FromStr;
use alpm_types::{Version, VersionComparison, VersionRequirement};
let requirement = VersionRequirement::from_str(">=1.5")?;
assert_eq!(requirement.comparison, VersionComparison::GreaterOrEqual);
assert_eq!(requirement.version, Version::from_str("1.5")?);
Fields§
§comparison: VersionComparison
Version comparison function
version: Version
Target version
Implementations§
Source§impl VersionRequirement
impl VersionRequirement
Sourcepub fn new(comparison: VersionComparison, version: Version) -> Self
pub fn new(comparison: VersionComparison, version: Version) -> Self
Create a new VersionRequirement
Sourcepub fn is_satisfied_by(&self, ver: &Version) -> bool
pub fn is_satisfied_by(&self, ver: &Version) -> bool
Returns true
if the requirement is satisfied by the given package version.
§Examples
use std::str::FromStr;
use alpm_types::{Version, VersionRequirement};
let requirement = VersionRequirement::from_str(">=1.5-3")?;
assert!(!requirement.is_satisfied_by(&Version::from_str("1.5")?));
assert!(requirement.is_satisfied_by(&Version::from_str("1.5-3")?));
assert!(requirement.is_satisfied_by(&Version::from_str("1.6")?));
assert!(requirement.is_satisfied_by(&Version::from_str("2:1.0")?));
assert!(!requirement.is_satisfied_by(&Version::from_str("1.0")?));
Sourcepub fn parser(input: &mut &str) -> ModalResult<Self>
pub fn parser(input: &mut &str) -> ModalResult<Self>
Recognizes a VersionRequirement
in a string slice.
Consumes all of its input.
§Errors
Returns an error if input
is not a valid alpm-comparison.
Trait Implementations§
Source§impl Clone for VersionRequirement
impl Clone for VersionRequirement
Source§fn clone(&self) -> VersionRequirement
fn clone(&self) -> VersionRequirement
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for VersionRequirement
impl Debug for VersionRequirement
Source§impl<'de> Deserialize<'de> for VersionRequirement
impl<'de> Deserialize<'de> for VersionRequirement
Source§fn 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
Source§impl Display for VersionRequirement
impl Display for VersionRequirement
Source§impl FromStr for VersionRequirement
impl FromStr for VersionRequirement
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new VersionRequirement
from a string slice.
Delegates to VersionRequirement::parser
.
§Errors
Returns an error if VersionRequirement::parser
fails.
Source§impl PartialEq for VersionRequirement
impl PartialEq for VersionRequirement
Source§impl Serialize for VersionRequirement
impl Serialize for VersionRequirement
impl Eq for VersionRequirement
impl StructuralPartialEq for VersionRequirement
Auto Trait Implementations§
impl Freeze for VersionRequirement
impl RefUnwindSafe for VersionRequirement
impl Send for VersionRequirement
impl Sync for VersionRequirement
impl Unpin for VersionRequirement
impl UnwindSafe for VersionRequirement
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
Mutably borrows from an owned value. Read more