pub struct Version {
pub pkgver: PackageVersion,
pub epoch: Option<Epoch>,
pub pkgrel: Option<PackageRelease>,
}
Expand description
A version of a package
A Version
tracks an optional Epoch
, a PackageVersion
and an optional PackageRelease
.
See alpm-package-version for details on the format.
§Examples
use std::str::FromStr;
use alpm_types::{Epoch, PackageRelease, PackageVersion, Version};
let version = Version::from_str("1:2-3")?;
assert_eq!(version.epoch, Some(Epoch::from_str("1")?));
assert_eq!(version.pkgver, PackageVersion::new("2".to_string())?);
assert_eq!(version.pkgrel, Some(PackageRelease::new(3, None)));
Fields§
§pkgver: PackageVersion
The version of the package
epoch: Option<Epoch>
The epoch of the package
pkgrel: Option<PackageRelease>
The release of the package
Implementations§
Source§impl Version
impl Version
Sourcepub fn new(
pkgver: PackageVersion,
epoch: Option<Epoch>,
pkgrel: Option<PackageRelease>,
) -> Self
pub fn new( pkgver: PackageVersion, epoch: Option<Epoch>, pkgrel: Option<PackageRelease>, ) -> Self
Create a new Version
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 PackageRelease
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 std::str::FromStr;
use alpm_types::Version;
assert_eq!(
Version::vercmp(&Version::from_str("1.0.0")?, &Version::from_str("0.1.0")?),
1
);
assert_eq!(
Version::vercmp(&Version::from_str("1.0.0")?, &Version::from_str("1.0.0")?),
0
);
assert_eq!(
Version::vercmp(&Version::from_str("0.1.0")?, &Version::from_str("1.0.0")?),
-1
);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Version
impl<'de> Deserialize<'de> for Version
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 Ord for Version
impl Ord for Version
Source§impl PartialOrd for Version
impl PartialOrd for Version
impl 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