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
vprefix or fewer than three parts) - Dot-separated numeric (e.g., date-based
2024.01.15or four-part1.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.
Opaque(String)
non-parseable version string where ordering cannot be determined.
Implementations§
Source§impl Version
impl Version
Sourcepub fn parse_lenient(s: &str) -> Self
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(_)));Sourcepub fn is_downgrade(&self, new: &Self) -> bool
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
dpkgversion-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§
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.