pub struct Version {
pub epoch: Option<u32>,
pub chunks: Chunks,
pub release: Option<Release>,
pub meta: Option<String>,
}Expand description
A version number with decent structure and comparison logic.
This is a descriptive scheme, meaning that it encapsulates the most
common, unconscious patterns that developers use when assigning version
numbers to their software. If not SemVer, most version numbers found in
the wild will parse as a Version. These generally conform to the x.x.x-x
pattern, and may optionally have an epoch.
Epochs
Epochs are prefixes marked by a colon, like in 1:2.3.4. When comparing two
Version values, epochs take precedent. So 2:1.0.0 > 1:9.9.9. If one of
the given Versions has no epoch, its epoch is assumed to be 0.
Examples
use versions::{SemVer, Version};
// None of these are SemVer, but can still be parsed and compared.
let vers = vec!["0.25-2", "8.u51-1", "20150826-1", "1:2.3.4"];
for v in vers {
assert!(SemVer::new(v).is_none());
assert!(Version::new(v).is_some());
}Fields§
§epoch: Option<u32>An optional prefix that marks that some paradigm shift in versioning has occurred between releases of some software.
chunks: ChunksThe main sections of the Version. Unlike SemVer, these sections
are allowed to contain letters.
release: Option<Release>This either indicates a prerelease like SemVer, or a “release”
revision for software packages. In the latter case, a version like
1.2.3-2 implies that the software itself hasn’t changed, but that this
is the second bundling/release (etc.) of that particular package.
meta: Option<String>Some extra metadata that doesn’t factor into comparison.
Implementations§
source§impl Version
impl Version
sourcepub fn nth(&self, n: usize) -> Option<u32>
pub fn nth(&self, n: usize) -> Option<u32>
Try to extract a position from the Version as a nice integer, as if it
were a SemVer.
use versions::Version;
let mess = Version::new("1:2.a.4.5.6.7-r1").unwrap();
assert_eq!(Some(2), mess.nth(0));
assert_eq!(None, mess.nth(1));
assert_eq!(Some(4), mess.nth(2));sourcepub fn nth_lenient(&self, n: usize) -> Option<u32>
pub fn nth_lenient(&self, n: usize) -> Option<u32>
Like nth, but pulls a number even if it was followed by letters.
Trait Implementations§
source§impl Ord for Version
impl Ord for Version
source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
If two epochs are equal, we need to compare their actual version numbers. Otherwise, the comparison of the epochs is the only thing that matters.
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq for Version
impl PartialEq for Version
source§impl PartialOrd for Version
impl PartialOrd for Version
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more