Skip to content

Ideas & resources for new crate design #20

@timvisee

Description

@timvisee

Here I describe some ideas, thoughts, resources and possible design decisions I
gathered during a brainstorm session to help developing a new crate design for
version-compare in the future. It lists things I like to have, some facts we
can use, a simple list of existing version schemes and so on.
I hope this helps to shed light on all desired features in a new design, by
distilling what is used currently.

Some things may not be implementable, might be incorrect and I'm probably
missing a lot. That's something to look into later.

Like to have

Here are some ideas I'd like to have:

  • Version & Ver to represent comparable version numbers
    Like String and str, owned and referenced
  • Easily compare Version and Ver instances
    Implement comparison traits, and useful helper functions,
    similar easy-to-use API to version-compare 0.0.10
  • Version schemes, for different version parsing and comparison logic (semver, gnu, ...)
  • Generic Version & Ver to compare on, do not use different structs for all
    kinds of different schemes
  • Great extensibility
    Allow users to externally define their own version schemes, to be a framework
    to compare different version styles as well. Good implementations could be
    merged into this crate later on.
    Also allow minimal configurability on some existing schemes, such as the
    generic/default scheme used for comparison to tweak sorting.
  • Stream the parsing version number components:
    Could speed things up when comparing large version strings
  • Validity checking
    Allow checking whether a version string is valid given a version scheme.
  • Configure comparison logic between each component type
    1! > 2: Epoch(1) > Major(2)
  • Compare across different version schemes (would this even even be possible?)
  • Support version operator expressions (Rust, npm)
    Testing operators such as > ,>=, !, *, ^, ~
    >=1.2, ^1, ~1.2.3, 1.2.*

Design facts

Here are some design facts/choices that I think will be assumed/used for the
redesign of this crate. This could be used to build the core Version and Ver
structs upon, allowing support for a large spectrum of version numbers:

  • Versions are sequence based (https://en.wikipedia.org/wiki/Software_versioning#Sequence-based_identifiers)
  • Versions can be represented as a string
  • Versions have components (might just be a single one)
  • Versions may have an arbitrary number of components
  • Version schemes may introduce any number of additional local constraints
  • Version components are always sequenced from major to minor (little-endian)

Not compatible with everything in ..., but compromises must be made:
https://xenoterracide.com/post/falsehoods-programmers-believe-about-versions/

Existing version schemes

Some version schemes that were mentioned and used right now. Could be used to
source mechanics from to validate a new crate design is sufficient, and version
schemes could be implemented for it:

Core version components

Component types that might be used globally in the core of the crate:

Special version components

Component types that might be a version scheme specific implementation:

  • Epoch
    • 1!: conda
    • 1:: RPM
  • Patch version
  • Pre-release version
    • SemVer
  • Build number
    • SemVer
  • VCS revision info
    • Git tag/commit
    • Mercurial
    • svn

Examples

Some version numbers I'd like to support, in different styles:

  • 1
  • 1.2.3
  • 1.2.alpha.3
  • 2.0.0-rc.2: semver
  • 1:1.2.3-debian2: Debian
  • 1!1.2.3-post: PEP440/conda
  • 1.0a0: conda: the a0 is separate from the 1 and 0 parts. Pre-release indicator.
  • 1.0.2b12: used by Apple
  • v1.2.3: common in tags
  • 19999.00071
  • YYYY-mm-dd: dates
  • YYYYmmdd: dates
  • 0.8.1+git.20100810t184654.ab580f4-0ubuntu2: dpkg package for git on Ubuntu
  • MyApp 3.2.0 / build 0932
  • 1.0.2d: openssl, which has releases with & without the letter, but will gain sanity soon.

And some components as well:

  • 1!: epoch in Conda
  • 1:: epoch in RPM
  • ~suffix: ~ is lowest when sorting in Debian
  • .suffix
  • -suffix
  • floating point value: in old PERL
  • 1a: letters in components
  • -1.2.3: negative components
  • 1.-2.3: negative components

Other resources

Some other useful resources, not really covered yet:

Edit: added suggestions from #20 (comment)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions