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::from_str("1:2-3").unwrap();
assert_eq!(version.epoch, Some(Epoch::from_str("1").unwrap()));
assert_eq!(version.pkgver, Pkgver::new("2".to_string()).unwrap());
assert_eq!(version.pkgrel, Some(Pkgrel::new("3".to_string()).unwrap()));
Fields§
§pkgver: Pkgver
§epoch: Option<Epoch>
§pkgrel: Option<Pkgrel>
Implementations§
source§impl Version
impl Version
sourcepub fn new(pkgver: Pkgver, epoch: Option<Epoch>, pkgrel: Option<Pkgrel>) -> Self
pub fn new(pkgver: Pkgver, epoch: Option<Epoch>, pkgrel: Option<Pkgrel>) -> 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 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 std::str::FromStr;
use alpm_types::Version;
assert_eq!(
Version::vercmp(
&Version::from_str("1.0.0").unwrap(),
&Version::from_str("0.1.0").unwrap()
),
1
);
assert_eq!(
Version::vercmp(
&Version::from_str("1.0.0").unwrap(),
&Version::from_str("1.0.0").unwrap()
),
0
);
assert_eq!(
Version::vercmp(
&Version::from_str("0.1.0").unwrap(),
&Version::from_str("1.0.0").unwrap()
),
-1
);
Trait Implementations§
source§impl FromStr for Version
impl FromStr for Version
source§fn from_str(s: &str) -> Result<Version, Self::Err>
fn from_str(s: &str) -> Result<Version, Self::Err>
Create a new Version
from a string slice.
Expects a composite version string such as 2:1.25.1-5
The components of the above composite version string are:
2
: The optional epoch, delimited with a:
1.25.1
: The version, which is an arbitrary ASCII string, excluding[':', '/', '-']
5
: The optional release, delimited with a-
.
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)