Skip to main content

Version

Enum Version 

Source
pub enum Version {
    Semver(Version),
    Numeric(Vec<u64>),
    Deb {
        epoch: u64,
        upstream: String,
        revision: String,
    },
    Opaque(String),
}
Expand description

parsed version representation for lenient comparison.

covers the common version formats found in SBOMs:

  • Standard semver (possibly with v prefix or fewer than three parts)
  • Dot-separated numeric (e.g., date-based 2024.01.15 or four-part 1.2.3.4)
  • Debian/RPM-style epoch:upstream-revision (dominant in OS/container SBOMs)
  • Opaque strings that cannot be compared

Variants§

§

Semver(Version)

parseable as semver (with lenient parsing: v/V prefix stripped, one- or two-part versions padded to three parts).

§

Numeric(Vec<u64>)

dot-separated numeric segments that don’t qualify as semver (e.g., four-part versions or versions with leading zeros).

§

Deb

Debian/RPM-style version with an optional numeric epoch and a trailing revision, compared with the Debian dpkg algorithm. covers epoch:upstream-revision (Debian), epoch:version-release (RPM), and PEP440 epoch!version forms that don’t parse as clean semver but whose ordering is still well-defined. an absent epoch is 0 and an absent revision is the empty string.

Fields

§epoch: u64
§upstream: String
§revision: String
§

Opaque(String)

non-parseable version string where ordering cannot be determined.

Implementations§

Source§

impl Version

Source

pub fn parse_lenient(s: &str) -> Self

parses a version string leniently.

tries semver first (stripping v/V prefix and padding one- or two-part versions), then dot-separated numeric, then Debian/RPM-style epoch/revision versions, then falls back to Opaque.

§Examples
use sbom_model::versions::Version;

assert!(matches!(Version::parse_lenient("1.2.3"), Version::Semver(_)));
assert!(matches!(Version::parse_lenient("v1.2"), Version::Semver(_)));
assert!(matches!(Version::parse_lenient("2024.01.15"), Version::Numeric(_)));
assert!(matches!(Version::parse_lenient("2:1.0-3"), Version::Deb { .. }));
assert!(matches!(Version::parse_lenient("abc"), Version::Opaque(_)));
Source

pub fn is_downgrade(&self, new: &Self) -> bool

returns true if new is a downgrade from self.

comparison strategy depends on the variant pair:

  • Semver vs Semver: semver precedence ordering (including pre-release; build metadata is ignored per SemVer §10)
  • Numeric vs Numeric: segment-by-segment with implicit zero padding
  • Semver vs Numeric (either direction): extracts [major, minor, patch] from the semver side and compares as numeric segments
  • Deb vs Deb: epoch (numeric), then upstream, then revision, via the Debian dpkg version-comparison algorithm
  • Any other pair (including any Opaque, or a Deb against a semver/numeric version): returns false (ordering unknown)
§Examples
use sbom_model::versions::Version;

let old = Version::parse_lenient("2.0.0");
let new = Version::parse_lenient("1.5.0");
assert!(old.is_downgrade(&new));

let old = Version::parse_lenient("1.0.0");
let new = Version::parse_lenient("2.0.0");
assert!(!old.is_downgrade(&new));

Trait Implementations§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Version

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Version

Source§

impl PartialEq for Version

Source§

fn eq(&self, other: &Version) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.