semver-diff
Find the release-type difference between two semantic versions — was it a major,
minor, or patch change (or one of their prerelease variants)? A faithful Rust port of
node-semver's diff and the
semver-diff npm package, built on the
semver crate.
use Version;
use ;
assert_eq!;
assert_eq!;
assert_eq!;
// Or straight from strings:
assert_eq!;
Why semver-diff?
The semver crate parses and compares versions, but doesn't tell you what kind of
bump separates two of them — the thing update notifiers, changelog generators, and
dependency dashboards actually want to show ("this is a minor update"). The
prerelease logic is subtle, so this is a small, well-tested port that matches
node-semver exactly.
[]
= "0.1"
API
| Item | Purpose |
|---|---|
diff(a, b) |
Option<Difference> between two Versions (None if equal) |
diff_str(a, b) |
Parse two &str versions and diff them |
Difference |
Major / PreMajor / Minor / PreMinor / Patch / PrePatch / PreRelease |
Difference::as_str() |
The node-semver name ("major", "premajor", …) |
Difference::is_prerelease() |
Whether it's one of the Pre* variants |
Behavior
- The most significant changed component decides the result; a
Pre*variant is returned when the higher version is itself a prerelease. - Stabilizing a prerelease (
1.2.0-rc→1.2.0) reports the release it became (Minorhere), matching node-semver. - The result is symmetric (
diff(a, b) == diff(b, a)) and ignores build metadata, just like SemVer precedence.
License
Licensed under either of Apache-2.0 or MIT at your option.