Struct proto::Version

pub struct Version<'input> {
    pub major: u64,
    pub minor: u64,
    pub patch: u64,
    pub additional: Additional,
    pub pre: PreRelease<'input>,
    pub build: Build<'input>,
}
Expand description

Represents a lenient semantic version number.

The version is bound to the lifetime of the input string.

Fields§

§major: u64

The major version.

§minor: u64

The minor version.

§patch: u64

The patch version.

§additional: Additional

additional version numbers.

§pre: PreRelease<'input>

The pre-release metadata.

§build: Build<'input>

The build metadata.

Implementations§

§

impl<'input> Version<'input>

pub const fn empty() -> Version<'input>

Constructs a new, empty version

Examples
let version = Version::empty();
assert_eq!(version.to_string(), "0.0.0")

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

Constructs a new version out of the three regular version components

Examples
let version = Version::new(1, 2, 3);
assert_eq!(version.to_string(), "1.2.3")

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

Parse a string slice into a Version.

This parser does not require semver-specification conformant input and is more lenient in what it allows. For more information, see [lenient_semver_parser].

Examples

let version = Version::parse("v1.2.3.4.5+build.42");
assert!(version.is_ok());

pub fn bump_major(&mut self)

Bumps the major version.

Sets minor, patch, and additional numbers to 0, removes pre-release and build identifier.

Examples

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_major();
assert_eq!(version.to_string(), "2.0.0.0.0");

pub fn bumped_major<'a>(&self) -> Version<'a>

Returns a new version with the major version bumped.

Sets minor, patch, and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples

let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_major().to_string(), "2.0.0.0.0");

pub fn bump_minor(&mut self)

Bumps the minor version.

Sets patch and additional numbers to 0, removes pre-release and build identifier.

Examples

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_minor();
assert_eq!(version.to_string(), "1.3.0.0.0");

pub fn bumped_minor<'a>(&self) -> Version<'a>

Returns a new version with the minor version bumped.

Sets patch and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples

let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_minor().to_string(), "1.3.0.0.0");

pub fn bump_patch(&mut self)

Bumps the patch version.

Sets any additional numbers to 0, removes pre-release and build identifier.

Examples

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_patch();
assert_eq!(version.to_string(), "1.2.4.0.0");

pub fn bumped_patch<'a>(&self) -> Version<'a>

Returns a new version with the patch version bumped.

Sets any additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples

let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_patch().to_string(), "1.2.4.0.0");

pub fn bump_additional(&mut self, index: usize)

Bumps any additional version.

Sets any following additional numbers to 0, removes pre-release and build identifier. If there are not enough additional numbers, only the pre-release and build identifier is removed.

Examples

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(0);
assert_eq!(version.to_string(), "1.2.3.5.0");

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(1);
assert_eq!(version.to_string(), "1.2.3.4.6");

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(2);
assert_eq!(version.to_string(), "1.2.3.4.5");

pub fn bumped_additional<'a>(&self, index: usize) -> Version<'a>

Returns a new version with the minor version bumped.

Sets patch and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples

let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_additional(0).to_string(), "1.2.3.5.0");
assert_eq!(version.bumped_additional(1).to_string(), "1.2.3.4.6");
assert_eq!(version.bumped_additional(2).to_string(), "1.2.3.4.5");

pub fn is_pre_release(&self) -> bool

Returns true if this version has pre-release metadata, i.e. it represents a pre-release.

Examples

let version = Version::parse("1").unwrap();
assert!(!version.is_pre_release());

let version = Version::parse("1-pre").unwrap();
assert!(version.is_pre_release());

let version = Version::parse("1+build").unwrap();
assert!(!version.is_pre_release());

pub fn disassociate_metadata<'a>( self ) -> (Version<'a>, PreRelease<'input>, Build<'input>)

Disassociate this Version by changing the lifetime to something new.

The returned is a copy of self without any metadata. Nothing in the new version references ’input, so we can change the lifetime to something else.

The existing identifiers for pre-release and build are returned as well, so that users can clone and re-add them.

Examples
use lenient_semver_parser::VersionBuilder;

let input = String::from("1-pre+build");
let version = Version::parse(&input).unwrap();

// couldn't drop input here
// drop(input);

let (mut version, pre, build) = version.disassociate_metadata::<'static>();

assert_eq!(Some("pre"), *pre);
assert_eq!(Some("build"), *build);

// now we can drop the input
drop(input);

// We can use the new version after it has be disassociated from `input`.
assert_eq!("1.0.0", version.to_string());

// only static metadata references are allowed now (because we said 'static earlier)
version.add_pre_release("pre2");
version.add_build("build2");

assert_eq!("1.0.0-pre2+build2", version.to_string());

Trait Implementations§

§

impl<'input> Clone for Version<'input>

§

fn clone(&self) -> Version<'input>

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
§

impl<'input> Debug for Version<'input>

§

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

Formats the value using the given formatter. Read more
§

impl Default for Version<'_>

§

fn default() -> Version<'_>

Returns the “default value” for a type. Read more
§

impl<'de, 'input> Deserialize<'de> for Version<'input>where 'de: 'input,

§

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

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

impl Display for Version<'_>

§

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

Formats the value using the given formatter. Read more
§

impl<'input> From<[u64; 1]> for Version<'input>

§

fn from(v: [u64; 1]) -> Version<'input>

Converts to this type from the input type.
§

impl<'input> From<[u64; 2]> for Version<'input>

§

fn from(v: [u64; 2]) -> Version<'input>

Converts to this type from the input type.
§

impl<'input> From<[u64; 3]> for Version<'input>

§

fn from(v: [u64; 3]) -> Version<'input>

Converts to this type from the input type.
§

impl<'input> From<(u64, u64)> for Version<'input>

§

fn from(_: (u64, u64)) -> Version<'input>

Converts to this type from the input type.
§

impl<'input> From<(u64, u64, u64)> for Version<'input>

§

fn from(_: (u64, u64, u64)) -> Version<'input>

Converts to this type from the input type.
§

impl<'input> From<u64> for Version<'input>

§

fn from(x: u64) -> Version<'input>

Converts to this type from the input type.
§

impl Hash for Version<'_>

§

fn hash<H>(&self, into: &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
§

impl Ord for Version<'_>

§

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<Self>,

Restrict a value to a certain interval. Read more
§

impl PartialEq<Version<'_>> for Version<'_>

§

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.
§

impl PartialOrd<Version<'_>> for Version<'_>

§

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
§

impl Serialize for Version<'_>

§

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
§

impl<'input> TryFrom<&'input str> for Version<'input>

§

type Error = Error<'input>

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

fn try_from( value: &'input str ) -> Result<Version<'input>, <Version<'input> as TryFrom<&'input str>>::Error>

Performs the conversion.
§

impl<'input> VersionBuilder<'input> for Version<'input>

§

type Out = Version<'input>

The return type of the final version.
§

fn new() -> Version<'input>

Construct a new version builder. Read more
§

fn set_major(&mut self, major: u64)

Set the major version component. Read more
§

fn set_minor(&mut self, minor: u64)

Set the minor version component. Read more
§

fn set_patch(&mut self, patch: u64)

Set the patch version component. Read more
§

fn add_additional(&mut self, num: u64)

Add additional numeric components following patch and preceding pre-release. Read more
§

fn add_pre_release(&mut self, pre_release: &'input str)

The pre-release metadata. Read more
§

fn add_build(&mut self, build: &'input str)

The build identifier. Read more
§

fn build(self) -> <Version<'input> as VersionBuilder<'input>>::Out

Construct the final version.
§

impl Eq for Version<'_>

Auto Trait Implementations§

§

impl<'input> RefUnwindSafe for Version<'input>

§

impl<'input> Send for Version<'input>

§

impl<'input> Sync for Version<'input>

§

impl<'input> Unpin for Version<'input>

§

impl<'input> UnwindSafe for Version<'input>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

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
source§

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

source§

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

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

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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>,

const: unstable · 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.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

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>,