compare_version

Crates.iocompare_version
lib.rscompare_version
version1.2.3
created_at2024-11-01 14:06:37.111996+00
updated_at2025-08-02 06:57:37.320334+00
descriptionA Rust library for comparing semantic versioning strings and checking version compatibility.
homepage
repositoryhttps://github.com/crates-dev/compare-version
max_upload_size
id1431822
size26,146
尤雨东 (eastspire)

documentation

README

compare_version

Official Documentation

A Rust library for comparing semantic versioning strings and checking version compatibility.

Features

  • Version Comparison: Compare two semantic versioning strings to determine their order (greater, less, equal).
  • Version Range Matching: Check if a specific version matches a specified range using ^ and ~ notation.
  • Pre-release Support: Handle pre-release versions with proper comparison logic.
  • Error Handling: Comprehensive error types to handle version parsing and range issues gracefully.

Installation

To use this crate, you can run cmd:

cargo add compare_version

Examples

use compare_version::*;

let result = CompareVersion::compare_version("1.2.3", "1.2.4");
assert_eq!(result, Ok(VersionComparison::Less));
let matches = CompareVersion::matches_version_range("1.2.3", "^1.2.0");
assert_eq!(matches, Ok(true));
let matches = CompareVersion::matches_version_range("1.2.3", "~1.2.4");
assert_eq!(matches, Ok(false));

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any inquiries, please reach out to the author at root@ltpp.vip.

Commit count: 0

cargo fmt