A Rust library to easily compare version numbers, and test them against various comparison operators.
Comparing version numbers is hard. Especially when version numbers get really complex, or when their formatting differs.
This library helps you to easily compare any kind of version number with a single code-statement.
Two version numbers can be compared to each other, to get a relevant comparison operator (<
, ==
, >
),
or version numbers can be tested against any given comparison operator.
Along with version comparison, the library also features other useful tools.
For example: version numbers can also be parsed to inspect a version number by it's bare parts if desired.
Inspired by PHP's version_compare().
Note: This library is still a work in progress. See the list below for a list of currently available and future features.
<
, ==
or >
.The following features will be added in a later version: * Version manifest, to specify detailed version number constraints. * Batch comparisons.
This library is very easy to use. Here's a basic usage example:
```rust // Define some version numbers let a = "1.2"; let b = "1.5.1";
// The following comparison operators are used: // - CompOp::Eq -> Equal // - CompOp::Ne -> Not equal // - CompOp::Lt -> Less than // - CompOp::Le -> Less than or equal // - CompOp::Ge -> Greater than or equal // - CompOp::Gt -> Greater than
// Easily compare VersionCompare::compare(&a, &b); // -> CompOp::Lt VersionCompare::compareto(&a, &b, &CompOp::Le); // -> true VersionCompare::compareto(&a, &b, &CompOp::Gt); // -> false
// Version string parsing let aver = Version::from(a).unwrap(); let bver = Version::from(b).unwrap();
// Directly compare versions aver.compare(&bver); // -> CompOp::Lt bver.compare(&aver); // -> CompOp::Gt aver.compareto(&b_ver, &CompOp::LT); // -> true
// Match match aver.compare(&bver) { CompOp::Lt => println!("Version a is less than b"), CompOp::Eq => println!("Version a is equal to b"), CompOp::Gt => println!("Version a is greater than b") } ```
This library is automatically build and tested for each commit using CI services.
|Service|Branch|Build Status| |
|---:|:---|:---:|:---|
|Travis CI|master||View Status|
|Travis CI|last commit|
|View Status|
This project is released under the GNU GPL-3.0 license. Check out the LICENSE file for more information.