Struct nextver::Version

source ·
pub struct Version<'vs, S: Scheme> { /* private fields */ }
Expand description

A Version object represents a specific point in a project’s development, comprised of values and literal text. It’s structure is defined by a Format. Versions can be displayed (to_string()), incremented (next()), and compared (partial_cmp()).

Version objects are created with the Scheme::new_version or Format::new_version methods.

§(In)Equality

Version objects only implement a partial ordering. This is because the ordering only makes sense when they have the same format. Therefore, comparisons between versions with different formats will always return false.

§Examples

use nextver::prelude::*;

let version = Sem::new_version("<MAJOR>.<MINOR>.<PATCH>", "1.2.3")?;

Or, use a previously created Format object:

use nextver::prelude::*;

let format = Sem::new_format("<MAJOR>.<MINOR>.<PATCH>")?;
let version = format.new_version("1.2.3")?;

Implementations§

source§

impl<'vs> Version<'vs, Sem>

source

pub fn next(&self, level: SemLevel) -> Result<Self, NextError>

Returns a new version where the value of specifier given by level is incremented, and all lesser semantic values are reset to zero. This is similar to how an odometer works.

§Example
use nextver::prelude::*;;

let cur = Sem::new_version("<MAJOR>.<MINOR>.<PATCH>", "1.2.3")?;
let next = cur.next(SemLevel::Major)?;
assert_eq!("2.0.0", &next.to_string());
assert!(cur < next);

let next_next = next.next(SemLevel::Patch)?;
assert_eq!("2.0.1", &next_next.to_string());
assert!(next < next_next);
§Errors

Returns a Result::Err of…

source§

impl<'vs> Version<'vs, Cal>

source

pub fn next(&self, date: Date) -> Result<Self, NextError>

Returns a new version where the values of all date specifiers is advanced to those in date.

If date is before the date in this version, an error is returned. (See Self::next_unchecked to skip this check.)

§Example
use nextver::prelude::*;;

let date = Date::utc_now();  // assume today is 2024-02-23

let cur = Cal::new_version("<YYYY>.<MM>", "2024.1")?;
let next = cur.next(date)?;
assert_eq!("2024.2", &next.to_string());
assert!(cur < next);
§Errors

Returns a Result::Err of…

source

pub fn next_unchecked(&self, date: Date) -> Result<Self, NextError>

Same as next, but without checking if date is after the date in this version.

§Errors

Same as next, but without NextError::NewDateIsBefore.

source§

impl<'vs> Version<'vs, CalSem>

source

pub fn next(&self, date: Date, level: CalSemLevel) -> Result<Self, NextError>

Returns a new version where the following are done in order:

  1. The values of all calendar specifiers are changed to those in date.
  2. A check is performed to see if the date has advanced. Then, one of the following is performed:
    • (date-is-different) Iff the date has advanced, all semantic values are reset to zero.
    • (date-is-same) Otherwise, the value of semantic specifier given by level is incremented, and all lesser semantic values are reset to zero. This is similar to how an odometer works.

If date is before the date in this version, an error is returned. (See next_unchecked to skip this check.)

§Example

In the date-is-different case:

use nextver::prelude::*;;

let date = Date::utc_now();  // assume today is 2024-02-23

let cur = CalSem::new_version("<YYYY>.<MM>.<PATCH>", "2024.1.123")?;
let next = cur.next(date, CalSemLevel::Patch)?;
assert_eq!("2024.2.0", &next.to_string());
assert!(cur < next);

In the date-is-same case:

use nextver::prelude::*;;

let date = Date::utc_now();  // assume today is 2024-02-23

let cur = CalSem::new_version("<YYYY>.<MM>.<PATCH>", "2024.2.123")?;
let next = cur.next(date, CalSemLevel::Patch)?;
assert_eq!("2024.2.124", &next.to_string());
assert!(cur < next);
§Errors

Returns a Result::Err of…

source

pub fn next_unchecked( &self, date: Date, level: CalSemLevel ) -> Result<Self, NextError>

Same as next, but without checking if date is after the date in this version.

§Errors

Same as next, but without NextError::NewDateIsBefore.

Trait Implementations§

source§

impl<'vs, S: Clone + Scheme> Clone for Version<'vs, S>

source§

fn clone(&self) -> Version<'vs, S>

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<'vs, S: Debug + Scheme> Debug for Version<'vs, S>

source§

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

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

impl<'vs, S: Scheme> Display for Version<'vs, S>

source§

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

Returns the rendered version string

source§

impl<'vs, S: PartialEq + Scheme> PartialEq for Version<'vs, S>

source§

fn eq(&self, other: &Version<'vs, S>) -> 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<'vs, S: Scheme> PartialOrd for Version<'vs, S>

source§

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

Compares two versions. This is only a partial ordering it is only meaningful to compare two versions when they come from the same format.

Returns None when either of the following are true:

  • The number of tokens in the versions are different. Tokens are either literal text or specifier values.
  • For two given tokens, they are not of the same type. E.g., one is a literal, one is a value.
  • For two given literal tokens, the text is not the same.
  • For two given value tokens, they are not of the same specifier type. E.g., one is a <YYYY> value, one is a <YY> value.
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<'vs, S: Eq + Scheme> Eq for Version<'vs, S>

source§

impl<'vs, S: Scheme> StructuralPartialEq for Version<'vs, S>

Auto Trait Implementations§

§

impl<'vs, S> RefUnwindSafe for Version<'vs, S>
where <S as Scheme>::Specifier: RefUnwindSafe,

§

impl<'vs, S> Send for Version<'vs, S>
where <S as Scheme>::Specifier: Sync,

§

impl<'vs, S> Sync for Version<'vs, S>
where <S as Scheme>::Specifier: Sync,

§

impl<'vs, S> Unpin for Version<'vs, S>

§

impl<'vs, S> UnwindSafe for Version<'vs, S>
where <S as Scheme>::Specifier: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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.

source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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.