Struct Version
struct Version { ... }
SemVer version as defined by https://semver.org.
Syntax
-
The major, minor, and patch numbers may be any integer 0 through u64::MAX. When representing a SemVer version as a string, each number is written as a base 10 integer. For example,
1.0.119. -
Leading zeros are forbidden in those positions. For example
1.01.00is invalid as a SemVer version. -
The pre-release identifier, if present, must conform to the syntax documented for
Prerelease. -
The build metadata, if present, must conform to the syntax documented for
BuildMetadata. -
Whitespace is not allowed anywhere in the version.
Total ordering
Given any two SemVer versions, one is less than, greater than, or equal to the other. Versions may be compared against one another using Rust's usual comparison operators.
-
The major, minor, and patch number are compared numerically from left to right, lexicographically ordered as a 3-tuple of integers. So for example version
1.5.0is less than version1.19.0, despite the fact that "1.19.0" < "1.5.0" as ASCIIbetically compared strings and 1.19 < 1.5 as real numbers. -
When major, minor, and patch are equal, a pre-release version is considered less than the ordinary release: version
1.0.0-alpha.1is less than version1.0.0. -
Two pre-releases of the same major, minor, patch are compared by lexicographic ordering of dot-separated components of the pre-release string.
-
Identifiers consisting of only digits are compared numerically:
1.0.0-pre.8is less than1.0.0-pre.12. -
Identifiers that contain a letter or hyphen are compared in ASCII sort order:
1.0.0-pre12is less than1.0.0-pre8. -
Any numeric identifier is always less than any non-numeric identifier:
1.0.0-pre.1is less than1.0.0-pre.x.
-
Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
Fields
major: u64minor: u64patch: u64pre: Prereleasebuild: BuildMetadata
Implementations
impl Version
const fn new(major: u64, minor: u64, patch: u64) -> SelfCreate
Versionwith an empty pre-release and build metadata.Equivalent to:
# use ; # # constfn parse(text: &str) -> Result<Self, Error>Create
Versionby parsing from string representation.Errors
Possible reasons for the parse to fail include:
-
1.0— too few numeric components. A SemVer version must have exactly three. If you are looking at something that has fewer than three numbers in it, it's possible it is aVersionReqinstead (with an implicit default^comparison operator). -
1.0.01— a numeric component has a leading zero. -
1.0.unknown— unexpected character in one of the components. -
1.0.0-or1.0.0+— the pre-release or build metadata are indicated present but empty. -
1.0.0-alpha_123— pre-release or build metadata have something outside the allowed characters, which are0-9,A-Z,a-z,-, and.(dot). -
23456789999999999999.0.0— overflow of a u64.
-
fn cmp_precedence(self: &Self, other: &Self) -> OrderingCompare the major, minor, patch, and pre-release value of two versions, disregarding build metadata. Versions that differ only in build metadata are considered equal. This comparison is what the SemVer spec refers to as "precedence".
Example
use Version; let mut versions = ; // This is a stable sort, so it preserves the relative order of equal // elements. The three 1.20.0 versions differ only in build metadata so // they are not reordered relative to one another. versions.sort_by; assert_eq!; // Totally order the versions, including comparing the build metadata. versions.sort; assert_eq!;
impl Clone for Version
fn clone(self: &Self) -> Version
impl Debug for crate::Version
fn fmt(self: &Self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result
impl Display for crate::Version
fn fmt(self: &Self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result
impl Eq for Version
impl Freeze for Version
impl FromStr for crate::Version
fn from_str(text: &str) -> Result<Self, <Self as >::Err>
impl Hash for Version
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for Version
fn cmp(self: &Self, other: &Version) -> $crate::cmp::Ordering
impl PartialEq for Version
fn eq(self: &Self, other: &Version) -> bool
impl PartialOrd for Version
fn partial_cmp(self: &Self, other: &Version) -> $crate::option::Option<$crate::cmp::Ordering>
impl RefUnwindSafe for Version
impl Send for Version
impl Serialize for crate::Version
fn serialize<S>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error> where S: Serializer
impl StructuralPartialEq for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
impl<'de> Deserialize for crate::Version
fn deserialize<D>(deserializer: D) -> Result<Self, <D as >::Error> where D: Deserializer<'de>
impl<T> Any for Version
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Version
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Version
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Version
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> DeserializeOwned for Version
impl<T> From for Version
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Version
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Version
fn to_string(self: &Self) -> String
impl<T, U> Into for Version
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Version
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Version
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>