Struct bones_asset::Version

source ·
pub struct Version {
    pub major: u64,
    pub minor: u64,
    pub patch: u64,
    pub pre: Prerelease,
    pub build: BuildMetadata,
}
Expand description

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.00 is 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.0 is less than version 1.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.1 is less than version 1.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.8 is less than 1.0.0-pre.12.

    • Identifiers that contain a letter or hyphen are compared in ASCII sort order: 1.0.0-pre12 is less than 1.0.0-pre8.

    • Any numeric identifier is always less than any non-numeric identifier: 1.0.0-pre.1 is less than 1.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: u64§minor: u64§patch: u64§pre: Prerelease§build: BuildMetadata

Implementations§

source§

impl Version

source

pub const fn new(major: u64, minor: u64, patch: u64) -> Version

Create Version with an empty pre-release and build metadata.

Equivalent to:

Version {
    major,
    minor,
    patch,
    pre: Prerelease::EMPTY,
    build: BuildMetadata::EMPTY,
}
source

pub fn parse(text: &str) -> Result<Version, Error>

Create Version by 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 a VersionReq instead (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- or 1.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 are 0-9, A-Z, a-z, -, and . (dot).

  • 23456789999999999999.0.0 — overflow of a u64.

source

pub fn cmp_precedence(&self, other: &Version) -> Ordering

Compare 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 semver::Version;

let mut versions = [
    "1.20.0+c144a98".parse::<Version>().unwrap(),
    "1.20.0".parse().unwrap(),
    "1.0.0".parse().unwrap(),
    "1.0.0-alpha".parse().unwrap(),
    "1.20.0+bc17664".parse().unwrap(),
];

// 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(Version::cmp_precedence);
assert_eq!(versions, [
    "1.0.0-alpha".parse().unwrap(),
    "1.0.0".parse().unwrap(),
    "1.20.0+c144a98".parse().unwrap(),
    "1.20.0".parse().unwrap(),
    "1.20.0+bc17664".parse().unwrap(),
]);

// Totally order the versions, including comparing the build metadata.
versions.sort();
assert_eq!(versions, [
    "1.0.0-alpha".parse().unwrap(),
    "1.0.0".parse().unwrap(),
    "1.20.0".parse().unwrap(),
    "1.20.0+bc17664".parse().unwrap(),
    "1.20.0+c144a98".parse().unwrap(),
]);

Trait Implementations§

source§

impl Clone for Version

source§

fn clone(&self) -> Version

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Version

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Version

source§

fn deserialize<D>( deserializer: D ) -> Result<Version, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Version

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl FromStr for Version

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(text: &str) -> Result<Version, <Version as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Version

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Version

source§

fn cmp(&self, other: &Version) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Version

source§

fn eq(&self, other: &Version) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Version

source§

fn partial_cmp(&self, other: &Version) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Version

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Version

source§

impl StructuralEq for Version

source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Comparable<K> for Qwhere Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> RawClone for Twhere T: Clone,

§

unsafe fn raw_clone(src: *const c_void, dst: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_clone_cb( ) -> Unsafe<&'static (dyn Fn(*const c_void, *mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawDrop for T

§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawEq for Twhere T: Eq,

§

unsafe fn raw_eq(a: *const c_void, b: *const c_void) -> bool

Get the hash of the type. Read more
§

fn raw_eq_cb( ) -> Unsafe<&'static (dyn Fn(*const c_void, *const c_void) -> bool + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawHash for Twhere T: Hash,

§

unsafe fn raw_hash(ptr: *const c_void) -> u64

Get the hash of the type. Read more
§

fn raw_hash_cb( ) -> Unsafe<&'static (dyn Fn(*const c_void) -> u64 + Send + Sync)>

Get a callback suitable for [SchemaData].
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> Serialize for Twhere T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer ) -> Result<(), ErrorImpl>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,