Skip to main content

compare

Function compare 

Source
pub fn compare(a: &str, b: &str) -> Option<Ordering>
Expand description

Order two versions, or None if either is not a version this can read.

Dotted integers, compared left to right, with a missing segment reading as zero so 2026.12 and 2026.12.0 are one release. A -suffix sorts before the same numbers without one, which is semver’s rule and the one a -rc needs; build metadata after + is ignored, also semver’s rule. Two pre-releases on the same numbers compare as text, which is coarser than semver’s per-identifier rule and enough for a gate: the answer only has to be stable.

This is deliberately the same rule usage-lib implements separately. Neither crate can depend on the other — this one has no dependencies at all — so the rule is written down at https://usage.jdx.dev/spec/argv and a parity test holds the two to it.