iTranslated by AI
[Rust] cargo-semver-checks is handy for compatibility checking
Cargo uses SemVer for version management. Furthermore, the rules for maintaining library compatibility are documented in SemVer Compatibility.
SemVer Compatibility categorizes changes as follows:
- Major change
Large-scale, breaking changes that increment the MAJOR version in SemVer. Such as deleting functions or structs. - Minor change
Compatibility-maintaining changes that increment MINOR or PATCH versions. Such as adding functions or structs. - Possibly-breaking change
Changes where the classification as a Major or Minor change varies by project. Such as changing the Rust version.
For example, making a breaking change like deleting an existing function and then bumping the version from 1.0.1 to 1.0.2 is not allowed.
While these serve as a reference when updating libraries, checking each one manually is tedious. This is where cargo-semver-checks, which automatically checks compatibility rules, comes in handy.
Let's consider the following case.
In version 1.0.0 of a certain crate, there was a struct named Error.
pub struct Error {}
Suppose you want to rename Error to ConfigError in version 1.1.0. To maintain compatibility, you attempted to add a type alias, but accidentally named it Err instead of Error. This breaks compatibility.
pub struct ConfigError {}
#[deprecated(note = "Use `ConfigError` instead.")]
pub type Err = ConfigError;
This is something a person might overlook. However, cargo-semver-checks will catch it perfectly.
--- failure enum_missing: pub enum removed or renamed ---
Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.23.0/src/lints/enum_missing.ron
Here is the corrected version:
pub struct ConfigError {}
#[deprecated(note = "Use `ConfigError` instead.")]
pub type Error = ConfigError;
There is also a GitHub Action, so it's a good idea to introduce it for now.
Discussion