pub fn normalize_operator_spacing(requirement: &str) -> Cow<'_, str>Expand description
Collapses whitespace between a range operator (>=, <=, >, <) and its version
number, e.g. ">= 1.0 < 2.0" becomes ">=1.0 <2.0".
Several ecosystem requirement grammars (Dart’s pubspec constraints, Composer’s version constraints) accept a space after a range operator, but the ecosystem’s own AND-splitting logic (splitting a requirement on whitespace to get individual clauses) would otherwise treat the operator and its version as separate clauses.
Borrows requirement unchanged when there is no spaced operator to collapse (the common
case) instead of always allocating — callers that check many candidate versions against
the same requirement should normalize once and reuse the result rather than re-normalizing
per candidate.
§Examples
assert_eq!(normalize_operator_spacing(">= 1.0 < 2.0"), ">=1.0 <2.0");
assert_eq!(normalize_operator_spacing(">=1.0 <2.0"), ">=1.0 <2.0");