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 crate::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 Version
s 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: Chunks
The main sections of the Version
. Unlike crate::SemVer
, these
sections are allowed to contain letters.
release: Option<Release>
This either indicates a prerelease like crate::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 crate::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 PartialOrd for Version
impl PartialOrd for Version
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 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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more