pub struct VersionUpdater { /* private fields */ }
Expand description

This struct allows to increment a version by specifying a configuration.

Useful if you don’t like the default increment rules of the crate.

use next_version::VersionUpdater;
use semver::Version;

let updated_version = VersionUpdater::new()
    .with_features_always_increment_minor(false)
    .with_breaking_always_increment_major(true)
    .increment(&Version::new(1, 2, 3), ["feat: commit 1", "fix: commit 2"]);

assert_eq!(Version::new(1, 3, 0), updated_version);

Implementations§

source§

impl VersionUpdater

source

pub fn new() -> Self

Constructs a new instance with the default rules of the crate.

If you don’t customize the struct further, it is equivalent to calling crate::NextVersion::next.

use next_version::{NextVersion, VersionUpdater};
use semver::Version;

let version = Version::new(1, 2, 3);
let commits = ["feat: commit 1", "fix: commit 2"];
let updated_version1 = VersionUpdater::new()
    .increment(&version, &commits);
let updated_version2 = version.next(&commits);

assert_eq!(updated_version1, updated_version2);
source

pub fn with_features_always_increment_minor( self, features_always_increment_minor: bool ) -> Self

Configures automatic minor version increments for feature changes.

  • When true is passed, a feature will always trigger a minor version update.
  • When false is passed, a feature will trigger:
    • a patch version update if the major version is 0.
    • a minor version update otherwise.

Default: false.

use semver::Version;
use next_version::VersionUpdater;

let commits = ["feat: make coffee"];
let version = Version::new(0, 2, 3);
assert_eq!(
    VersionUpdater::new()
        .with_features_always_increment_minor(true)
        .increment(&version, &commits),
    Version::new(0, 3, 0)
);
assert_eq!(
    VersionUpdater::new()
        .increment(&version, &commits),
    Version::new(0, 2, 4)
);
source

pub fn with_breaking_always_increment_major( self, breaking_always_increment_major: bool ) -> Self

Configures 0 -> 1 major version increments for breaking changes.

  • When true is passed, a breaking change commit will always trigger a major version update (including the transition from version 0 to 1)
  • When false is passed, a breaking change commit will trigger:
    • a minor version update if the major version is 0.
    • a major version update otherwise.

Default: false.

use semver::Version;
use next_version::VersionUpdater;

let commits = ["feat!: incompatible change"];
let version = Version::new(0, 2, 3);
assert_eq!(
    VersionUpdater::new()
        .with_breaking_always_increment_major(true)
        .increment(&version, &commits),
    Version::new(1, 0, 0)
);
assert_eq!(
    VersionUpdater::new()
        .increment(&version, &commits),
    Version::new(0, 3, 0)
);
source

pub fn increment<I>(self, version: &Version, commits: I) -> Version
where I: IntoIterator, I::Item: AsRef<str>,

Analyze commits and determine the next version.

Trait Implementations§

source§

impl Debug for VersionUpdater

source§

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

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

impl Default for VersionUpdater

source§

fn default() -> Self

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

Auto Trait Implementations§

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