pub struct MinimalVersion {
pub pkgver: PackageVersion,
pub epoch: Option<Epoch>,
}
Expand description
A package version without a PackageRelease
.
Tracks an optional Epoch
and a PackageVersion
, but no PackageRelease
.
This reflects the minimal and minimal with epoch forms of alpm-package-version.
§Notes
- If
PackageRelease
should be optional for your use-case, useVersion
instead. - If
PackageRelease
should be mandatory for your use-case, useFullVersion
instead.
§Examples
use std::str::FromStr;
use alpm_types::MinimalVersion;
// A minimal version.
let version = MinimalVersion::from_str("1.0.0")?;
// A minimal version with epoch.
let version = MinimalVersion::from_str("1:1.0.0")?;
Fields§
§pkgver: PackageVersion
The version of the package
epoch: Option<Epoch>
The epoch of the package
Implementations§
Source§impl MinimalVersion
impl MinimalVersion
Sourcepub fn new(pkgver: PackageVersion, epoch: Option<Epoch>) -> Self
pub fn new(pkgver: PackageVersion, epoch: Option<Epoch>) -> Self
Creates a new MinimalVersion
.
§Examples
use alpm_types::{Epoch, MinimalVersion, PackageVersion};
// A minimal version.
let version = MinimalVersion::new(PackageVersion::new("1.0.0".to_string())?, None);
// A minimal version with epoch.
let version = MinimalVersion::new(
PackageVersion::new("1.0.0".to_string())?,
Some(Epoch::new(1.try_into()?)),
);
Sourcepub fn vercmp(&self, other: &MinimalVersion) -> i8
pub fn vercmp(&self, other: &MinimalVersion) -> i8
Compares self
to another MinimalVersion
and returns a number.
1
ifself
is newer thanother
0
ifself
andother
are equal-1
ifself
is older thanother
This output behavior is based on the behavior of the vercmp tool.
Delegates to MinimalVersion::cmp
for comparison.
The rules and algorithms used for comparison are explained in more detail in
alpm-package-version and alpm-pkgver.
§Examples
use std::str::FromStr;
use alpm_types::MinimalVersion;
assert_eq!(
MinimalVersion::from_str("1.0.0")?.vercmp(&MinimalVersion::from_str("0.1.0")?),
1
);
assert_eq!(
MinimalVersion::from_str("1.0.0")?.vercmp(&MinimalVersion::from_str("1.0.0")?),
0
);
assert_eq!(
MinimalVersion::from_str("0.1.0")?.vercmp(&MinimalVersion::from_str("1.0.0")?),
-1
);
Sourcepub fn parser(input: &mut &str) -> ModalResult<Self>
pub fn parser(input: &mut &str) -> ModalResult<Self>
Recognizes a MinimalVersion
in a string slice.
Consumes all of its input.
§Errors
Returns an error if input
is not a valid alpm-package-version (full or full with
epoch).
Trait Implementations§
Source§impl Clone for MinimalVersion
impl Clone for MinimalVersion
Source§fn clone(&self) -> MinimalVersion
fn clone(&self) -> MinimalVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MinimalVersion
impl Debug for MinimalVersion
Source§impl<'de> Deserialize<'de> for MinimalVersion
impl<'de> Deserialize<'de> for MinimalVersion
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>,
Source§impl Display for MinimalVersion
impl Display for MinimalVersion
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<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 FromStr for MinimalVersion
impl FromStr for MinimalVersion
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new MinimalVersion
from a string slice.
Delegates to MinimalVersion::parser
.
§Errors
Returns an error if Version::parser
fails.
Source§impl Ord for MinimalVersion
impl Ord for MinimalVersion
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares self
to another MinimalVersion
.
The comparison rules and algorithms are explained in more detail in alpm-package-version and alpm-pkgver.
§Examples
use std::{cmp::Ordering, str::FromStr};
use alpm_types::MinimalVersion;
// Examples for "minimal"
let version_a = MinimalVersion::from_str("0.1.0")?;
let version_b = MinimalVersion::from_str("1.0.0")?;
assert_eq!(version_a.cmp(&version_b), Ordering::Less);
assert_eq!(version_b.cmp(&version_a), Ordering::Greater);
let version_a = MinimalVersion::from_str("1.0.0")?;
let version_b = MinimalVersion::from_str("1.0.0")?;
assert_eq!(version_a.cmp(&version_b), Ordering::Equal);
// Examples for "minimal with epoch"
let version_a = MinimalVersion::from_str("1:1.0.0")?;
let version_b = MinimalVersion::from_str("1.0.0")?;
assert_eq!(version_a.cmp(&version_b), Ordering::Greater);
assert_eq!(version_b.cmp(&version_a), Ordering::Less);
let version_a = MinimalVersion::from_str("1:1.0.0")?;
let version_b = MinimalVersion::from_str("1:1.0.0")?;
assert_eq!(version_a.cmp(&version_b), Ordering::Equal);