Expand description
Defines modified syntax for version constraints.
§NIH?
The semver crate’s Version
is fine. What’s not fine is their VersionReq.
The reason we’re rolling our own instead of using something like the semver crate is that the requirements for elba conflict with what semver provides. The vector-of-predicate approach which semver provides is too flexible, making it harder to validate versions and perform operations on them (check if one range is a subset of another, etc.). The semver crate also provides some unnecessary operations.
Instead, this module adds features in some places and removes others for flexibility where it matters for elba.
§Functionality
Versions in elba take lots of good ideas from Cargo and Pub (Dart) versioning. We follow
Cargo’s compatibility rules for 0.* and 0.0.* versions to allow for less-stable packages.
Additionally, we also follow Cargo’s rules when sigils are omitted.
However, we purposely elide star notation since it’s unnecessary; 0.* == 0
, 0.0.* == 0.0
.
To make parsing easier, <
or <=
must always precede >
or >=
, like with Pub. Nonsensical
requirements like < 1 > 2
which are valid parses under semver get caught during parsing here.
In general, syntax is substantially stricter than in Cargo, and nonsensical constraints are
caught immediately when creating the constraint.
Structs§
- A set of
Range
s combines to make aConstraint
.Constraint
s are the union of multipleRange
s. Upon manual creation or updating of aConstraint
, theConstraint
will unify all of itsRange
s such that all of theRange
s are disjoint. Unification is eager: it’s done whenever the set is modified to keep the internal representation of the set unified at all times (this is useful for converting theConstraint
to a string, since theDisplay
trait doesn’t allow mutating self). - A continguous range in which a version can fall into. Syntax for ranges mirrors that of Pub or Cargo. Ranges can accept caret and tilde syntax, as well as less-than/greater-than specifications (just like Cargo). Like Pub, the
any
Range is completely unbounded on both sides. Pre-releaseVersion
s can satisfy aRange
iff theRange
mentions a pre-releaseVersion
on either bound, or if theRange
is unbounded on the upper side. Additionally, if a greater-than and/or less-thanRange
also has a!
after the inequality symbol, the Range will include pre-release versions.>=! 1.0.0
accepts all pre-releases of 1.0.0, along with the greater versions.<! 2.0.0
includes pre-releases of 2.0.0. >! and > mean the same thing, as do <=! and <=. - Represents a version number conforming to the semantic versioning scheme.