Gem version
Implement Ruby's Gem::Version
comparison logic in Rust.
See also: Gem::Version tests
The main use case is for the Heroku Ruby buildpack https://github.com/heroku/buildpacks-ruby and associated ecosystem of managing Ruby logic inside of Rust.
Install
Add it to your Cargo.toml:
$ cargo add gem_version
Use
use FromStr;
use GemVersion;
let version = from_str.unwrap;
assert!;
Diverging behavior
Ruby's Gem::Version
reference implementation converts - to .pre.
(commit).
This means the value you put in is not the value you get out:
puts Gem::Version.new()
# => "1.0.0.pre.alpha1"
It seems the coupling between comparison logic and representation was accidental at the time of introduction. This library diverges by showing the original string (and decoupling that from the comparison representation):
use FromStr;
use GemVersion;
let version = from_str.unwrap;
// Version does not have `.pre.` in it:
assert_eq!;
// But it performs comparisons as if it did:
assert_eq!;
If you want the upstream (reference) behavior that also changes the display output,
you can make a newtype that uses replace("-", ".pre.") on the input String.