pub struct Version { /* private fields */ }Expand description
Represents a RubyGems version with full semantic compatibility.
Implements the same parsing and comparison rules as Ruby’s Gem::Version:
- Dot-separated segments (numeric and string)
- Trailing zeros are ignored in comparisons (
1.0 == 1.0.0) - String segments denote pre-release versions
- Pre-release versions sort before their release counterparts
§Examples
use gem_audit::version::Version;
let v1 = Version::parse("1.2.3").unwrap();
let v2 = Version::parse("1.2.4").unwrap();
assert!(v1 < v2);
let pre = Version::parse("1.0.0.alpha").unwrap();
let release = Version::parse("1.0.0").unwrap();
assert!(pre < release);Implementations§
Source§impl Version
impl Version
Sourcepub fn parse(input: &str) -> Result<Self, VersionError>
pub fn parse(input: &str) -> Result<Self, VersionError>
Parse a version string into a Version.
Follows RubyGems parsing rules:
- Segments are split by
. - Within each segment, numeric and alphabetic parts are separated
- Leading zeros in numeric segments are stripped
- Hyphens are converted to
.pre. - Empty string becomes version “0”
Sourcepub fn is_prerelease(&self) -> bool
pub fn is_prerelease(&self) -> bool
Returns true if this version is a pre-release.
A version is pre-release if any of its segments is a string.
Trait Implementations§
Source§impl Ord for Version
impl Ord for Version
Source§impl PartialOrd for Version
impl PartialOrd for Version
impl Eq 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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§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
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.