Struct next_version::VersionUpdater
source · 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
impl VersionUpdater
sourcepub fn new() -> Self
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);
sourcepub fn with_features_always_increment_minor(
self,
features_always_increment_minor: bool
) -> Self
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)
);
sourcepub fn with_breaking_always_increment_major(
self,
breaking_always_increment_major: bool
) -> Self
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)
);
Trait Implementations§
source§impl Debug for VersionUpdater
impl Debug for VersionUpdater
Auto Trait Implementations§
impl RefUnwindSafe for VersionUpdater
impl Send for VersionUpdater
impl Sync for VersionUpdater
impl Unpin for VersionUpdater
impl UnwindSafe for VersionUpdater
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more