Rust library: version-compare
Rust library to easily compare version numbers with no specific format, and test against various comparison operators.
Comparing version numbers is hard, especially with weird version number formats.
This library helps you to easily compare any kind of version number with no
specific format using a best-effort approach.
Two version numbers can be compared to each other to get a comparison operator
(<
, ==
, >
), or test them against a comparison operator.
Along with version comparison, the library provides various other tools for working with version numbers.
Inspired by PHPs version_compare().
Note: Still a work in progress. Configurability is currently very limited. Things will change.
Formats
Version numbers that would parse successfully include:
1
, 3.10.4.1
, 1.2.alpha
, 1.2.dev.4
,
, . -32 . 1
, MyApp 3.2.0 / build 0932
...
See a list of how version numbers compare here.
Example
This library is very easy to use. Here's a basic usage example:
Cargo.toml
:
[]
= "0.1"
use ;
See the examples
directory for more.
Features
- Compare version numbers, get:
<
,==
,>
- Compare against a comparison operator
(
<
,<=
,==
,!=
,>=
,>
) - Parse complex and unspecified formats
- Static, standalone methods to easily compare version strings in a single line of code
Future ideas
- Version ranges
- Support for npm-style operators (e.g.
^1.0
or~1.0
) - Manifest: extend
Manifest
for to support a wide set of constraints - Building blocks for building your own specific version number parser
- Batch comparisons
Semver
Version numbers using the semver format are compared correctly with no additional configuration.
If your version number strings follow this exact format you may be better off
using the semver
crate for more format
specific features.
If that isn't certain however, version-compare
makes comparing a breeze.
Builds
This library is automatically build and tested every day and for each commit using CI services.
See the current status here: https://gitlab.com/timvisee/version-compare/-/pipelines
License
This project is released under the MIT license. Check out the LICENSE file for more information.