All Projects → timvisee → version-compare

timvisee / version-compare

Licence: MIT license
↔️ Rust library to easily compare version strings. Mirror from https://gitlab.com/timvisee/version-compare

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to version-compare

colorful
Make your terminal output colorful.
Stars: ✭ 43 (+34.38%)
Mutual labels:  crates, rust-library
Rusticsom
Rust library for Self Organising Maps (SOM).
Stars: ✭ 18 (-43.75%)
Mutual labels:  crates, rust-library
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (+228.13%)
Mutual labels:  crates
crates
crates is an extension aims to help people to manage their dependencies for rust (crates.io & TOML).
Stars: ✭ 156 (+387.5%)
Mutual labels:  crates
grids
A grid comparison standard
Stars: ✭ 74 (+131.25%)
Mutual labels:  comparison
fitparse-rs
Rust library to parse FIT formatted files
Stars: ✭ 20 (-37.5%)
Mutual labels:  crates
otp
One Time Password for 2-Factor-Authentication implemented in Rust
Stars: ✭ 21 (-34.37%)
Mutual labels:  rust-library
InputBot
A Rust library for creating global hotkeys, and emulating inputs.
Stars: ✭ 246 (+668.75%)
Mutual labels:  rust-library
inline-c-rs
Write and execute C code inside Rust.
Stars: ✭ 121 (+278.13%)
Mutual labels:  rust-library
intersection-wasm
Mesh-Mesh and Triangle-Triangle Intersection tests based on the algorithm by Tomas Akenine-Möller
Stars: ✭ 17 (-46.87%)
Mutual labels:  rust-library
rust-cross-libs
Cross-compile the Rust standard library for custom targets without a full bootstrap build.
Stars: ✭ 29 (-9.37%)
Mutual labels:  rust-library
ctrs
Category Theory For Programmers (Bartosz Milewski)
Stars: ✭ 62 (+93.75%)
Mutual labels:  rust-library
bitcrust
Bitcoin software suite
Stars: ✭ 61 (+90.63%)
Mutual labels:  rust-library
mpris-rs
Idiomatic MPRIS D-Bus interface library for Rust
Stars: ✭ 37 (+15.63%)
Mutual labels:  rust-library
twang
Library for pure Rust advanced audio synthesis.
Stars: ✭ 83 (+159.38%)
Mutual labels:  rust-library
rspark
▁▂▆▇▁▄█▁ Sparklines for Rust apps
Stars: ✭ 50 (+56.25%)
Mutual labels:  rust-library
parver
Parse and manipulate version numbers.
Stars: ✭ 41 (+28.13%)
Mutual labels:  version
hassle-rs
🦀 This crate provides an FFI layer and idiomatic rust wrappers for the new DirectXShaderCompiler library.
Stars: ✭ 34 (+6.25%)
Mutual labels:  rust-library
lcs-image-diff-rs
🖼 Image diff tool with LCS algorithm
Stars: ✭ 67 (+109.38%)
Mutual labels:  rust-library
kul
A unique textual notation that can be used as both a data format and a markup language and that has powerful extensibility of both lexical syntax and semantics, and a Rust library for parsing it.
Stars: ✭ 12 (-62.5%)
Mutual labels:  rust-library

Build status on GitLab CI Crate version Documentation Download statistics Coverage status Dependencies License

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:

[dependencies]
version-compare = "0.1"

example.rs:

use version_compare::{compare, compare_to, Cmp, Version};

fn main() {
    let a = "1.2";
    let b = "1.5.1";

    // The following comparison operators are used:
    // - Cmp::Eq -> Equal
    // - Cmp::Ne -> Not equal
    // - Cmp::Lt -> Less than
    // - Cmp::Le -> Less than or equal
    // - Cmp::Ge -> Greater than or equal
    // - Cmp::Gt -> Greater than

    // Easily compare version strings
    assert_eq!(compare(a, b), Ok(Cmp::Lt));
    assert_eq!(compare_to(a, b, Cmp::Le), Ok(true));
    assert_eq!(compare_to(a, b, Cmp::Gt), Ok(false));

    // Parse and wrap version strings as a Version
    let a = Version::from(a).unwrap();
    let b = Version::from(b).unwrap();

    // The Version can easily be compared with
    assert_eq!(a < b, true);
    assert_eq!(a <= b, true);
    assert_eq!(a > b, false);
    assert_eq!(a != b, true);
    assert_eq!(a.compare(&b), Cmp::Lt);
    assert_eq!(a.compare_to(&b, Cmp::Lt), true);

    // Or match the comparison operators
    match a.compare(b) {
        Cmp::Lt => println!("Version a is less than b"),
        Cmp::Eq => println!("Version a is equal to b"),
        Cmp::Gt => println!("Version a is greater than b"),
        _ => unreachable!(),
    }
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].