Struct alpm_types::Version
source · pub struct Version {
pub pkgver: Pkgver,
pub epoch: Option<Epoch>,
pub pkgrel: Option<Pkgrel>,
}
Expand description
A version of a package
A Version
tracks an optional Epoch
, a Pkgver
and an optional Pkgrel
.
§Examples
use std::str::FromStr;
use alpm_types::{Epoch, Pkgrel, Pkgver, Version};
let version = Version::new("1:1-1").unwrap();
assert_eq!(version.epoch, Some(Epoch::new("1").unwrap()));
assert_eq!(version.pkgver, Pkgver::new("1".to_string()).unwrap());
assert_eq!(version.pkgrel, Some(Pkgrel::new("1".to_string()).unwrap()));
Fields§
§pkgver: Pkgver
§epoch: Option<Epoch>
§pkgrel: Option<Pkgrel>
Implementations§
source§impl Version
impl Version
sourcepub fn new(version: &str) -> Result<Self, Error>
pub fn new(version: &str) -> Result<Self, Error>
Create a new Version from a string and return it in a Result
sourcepub fn with_pkgrel(version: &str) -> Result<Self, Error>
pub fn with_pkgrel(version: &str) -> Result<Self, Error>
Create a new Version, which is guaranteed to have a Pkgrel
sourcepub fn vercmp(a: &Version, b: &Version) -> i8
pub fn vercmp(a: &Version, b: &Version) -> i8
Compare two Versions and return a number
The comparison algorithm is based on libalpm/ pacman’s vercmp behavior.
1
ifa
is newer thanb
0
ifa
andb
are considered to be the same version-1
ifa
is older thanb
§Examples
use alpm_types::Version;
assert_eq!(Version::vercmp(&Version::new("1.0.0").unwrap(), &Version::new("0.1.0").unwrap()), 1);
assert_eq!(Version::vercmp(&Version::new("1.0.0").unwrap(), &Version::new("1.0.0").unwrap()), 0);
assert_eq!(Version::vercmp(&Version::new("0.1.0").unwrap(), &Version::new("1.0.0").unwrap()), -1);
Trait Implementations§
source§impl Ord for Version
impl Ord for Version
source§impl PartialEq for Version
impl PartialEq for Version
source§impl PartialOrd for Version
impl PartialOrd for Version
1.0.0 · source§fn 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 moreimpl Eq for Version
impl StructuralPartialEq for Version
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
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