pub struct Version {
pub pkgver: PackageVersion,
pub epoch: Option<Epoch>,
pub pkgrel: Option<PackageRelease>,
}Expand description
A version of a package
A Version generically tracks an optional Epoch, a PackageVersion and an optional
PackageRelease.
See alpm-package-version for details on the format.
§Notes
- If
PackageReleaseshould be mandatory for your use-case, useFullVersioninstead. - If
PackageReleaseshould not be used in your use-case, useMinimalVersioninstead.
§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: PackageVersionThe 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 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.
1ifais newer thanb0ifaandbare considered to be the same version-1ifais 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 From<&FullVersion> for Version
impl From<&FullVersion> for Version
Source§fn from(value: &FullVersion) -> Self
fn from(value: &FullVersion) -> Self
Creates a Version from a FullVersion reference.
Source§impl From<&MinimalVersion> for Version
impl From<&MinimalVersion> for Version
Source§fn from(value: &MinimalVersion) -> Self
fn from(value: &MinimalVersion) -> Self
Creates a Version from a MinimalVersion reference.
Source§impl From<FullVersion> for Version
impl From<FullVersion> for Version
Source§fn from(value: FullVersion) -> Self
fn from(value: FullVersion) -> Self
Creates a Version from a FullVersion.
Source§impl From<MinimalVersion> for Version
impl From<MinimalVersion> for Version
Source§fn from(value: MinimalVersion) -> Self
fn from(value: MinimalVersion) -> Self
Creates a Version from a MinimalVersion.
Source§impl Ord for Version
impl Ord for Version
Source§impl PartialOrd for Version
impl PartialOrd for Version
Source§impl TryFrom<&Version> for FullVersion
impl TryFrom<&Version> for FullVersion
Source§impl TryFrom<&Version> for MinimalVersion
impl TryFrom<&Version> for MinimalVersion
Source§impl TryFrom<Version> for FullVersion
impl TryFrom<Version> for FullVersion
Source§impl TryFrom<Version> for MinimalVersion
impl TryFrom<Version> for MinimalVersion
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