pub struct PackageVersion(pub(crate) String);
Expand description
A pkgver of a package
PackageVersion is used to denote the upstream version of a package.
A PackageVersion wraps a String
, which is guaranteed to only contain alphanumeric characters,
"_"
, "+"
or "."
, but to not start with a "_"
, a "+"
or a "."
character and to be at
least one char long.
NOTE: This implementation of PackageVersion is stricter than that of libalpm/pacman. It does not
allow empty strings ""
, or chars that are not in the allowed set, or "."
as the first
character.
§Examples
use std::str::FromStr;
use alpm_types::PackageVersion;
assert!(PackageVersion::new("1".to_string()).is_ok());
assert!(PackageVersion::new("1.1".to_string()).is_ok());
assert!(PackageVersion::new("foo".to_string()).is_ok());
assert!(PackageVersion::new("0".to_string()).is_ok());
assert!(PackageVersion::new(".0.1".to_string()).is_err());
assert!(PackageVersion::new("_1.0".to_string()).is_err());
assert!(PackageVersion::new("+1.0".to_string()).is_err());
Tuple Fields§
§0: String
Implementations§
Source§impl PackageVersion
impl PackageVersion
Sourcepub fn new(pkgver: String) -> Result<Self, Error>
pub fn new(pkgver: String) -> Result<Self, Error>
Create a new PackageVersion from a string and return it in a Result
Sourcepub fn segments(&self) -> VersionSegments<'_> ⓘ
pub fn segments(&self) -> VersionSegments<'_> ⓘ
Return an iterator over all segments of this version.
Sourcepub fn parser(input: &mut &str) -> ModalResult<Self>
pub fn parser(input: &mut &str) -> ModalResult<Self>
Recognizes a PackageVersion
in a string slice.
Consumes all of its input.
§Errors
Returns an error if input
is not a valid alpm-pkgrel.
Trait Implementations§
Source§impl Clone for PackageVersion
impl Clone for PackageVersion
Source§fn clone(&self) -> PackageVersion
fn clone(&self) -> PackageVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PackageVersion
impl Debug for PackageVersion
Source§impl<'de> Deserialize<'de> for PackageVersion
impl<'de> Deserialize<'de> for PackageVersion
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 PackageVersion
impl Display for PackageVersion
Source§impl FromStr for PackageVersion
impl FromStr for PackageVersion
Source§impl Ord for PackageVersion
impl Ord for PackageVersion
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
This block implements the logic to determine which of two package versions is newer or whether they’re considered equal.
This logic is surprisingly complex as it mirrors the current C-alpmlib implementation for backwards compatibility reasons. https://gitlab.archlinux.org/pacman/pacman/-/blob/a2d029388c7c206f5576456f91bfbea2dca98c96/lib/libalpm/version.c#L83-217