Crates.io | ver-cmp |
lib.rs | ver-cmp |
version | 0.1.4 |
source | src |
created_at | 2024-02-11 00:33:05.068484 |
updated_at | 2024-03-08 05:10:28.60945 |
description | A simple version comparison tool and library |
homepage | |
repository | |
max_upload_size | |
id | 1135414 |
size | 14,641 |
Ver-CMP is a useful cli-tool and library for comparing semantic versions
[!NOTE] The current minimum supported Rust version is: 1.60.0 (Last checked on 3/7/2024)
To build the cli tool, run the following command:
cargo build --bin ver_cmp_cli --features build-binary --release
The cli tool can be used to compare two versions and print out the comparison in many different formats
ver-cmp --ver1 0.2.3 --ver2 0.2.1
Output: 0.2.3 (the greater version)
ver-cmp --ver1 0.2.3 --ver2 0.2.1 -c
Output: 0 (indicates ver1 > ver2)
[!TIP] The -c or --compare flag to return a 0 1 or 2 meaning greater, less, or equal respectively; this can be used to easily pipe the output to other commands
This example shows how to use the library to compare two versions and print out the comparison
use ver_cmp::*;
fn main() {
let ver1 = "1.1.5";
let ver2 = "1.0.3";
let result = compare_versions(ver1, ver2);
match result {
Ok(Ordering::Greater) => println!("{} > {}", ver1, ver2),
Ok(Ordering::Less) => println!("{} < {}", ver1, ver2),
Ok(Ordering::Equal) => println!("{} == {}", ver1, ver2),
Err(e) => println!("Error: {}", e),
}
}
You can also take a look in the tests for more examples of how to use the library