Okay. On my range branch, I’ve implemented my proposal: https://github.com/steveklabnik/semver/tree/range
Here it is, from the top:
The semver crate has two modules, version and range.
semver::version
The Version struct represents a version.
pub struct Version {
pub major: u32,
pub minor: u32,
pub patch: u32,
pub pre: Vec<Identifier>,
pub build: Vec<Identifier>,
}
A u32 should be big enough for everything.
An identifer represents the build metadata and prerelease information.
pub enum Identifier {
Numeric(u64),
AlphaNumeric(String),
}
We need a u64 here, because often a date is used as metadata, and those can be pretty large, number-wise.
pub fn parse(s: &str) -> Result<Version, ParseError>
This function creates a Version. I’m wondering if it should remain a free function, or if it should be a static method on Version. I think version::parse("1.0.0") is a pretty nice interface, but Version.parse("1.0.0") might too. This is kind of a taste thing. @aturon, what do you think?
pub enum ParseError {
NonAsciiIdentifier,
IncorrectParse(Version, String),
GenericFailure,
}
Here’s the ways that a parse can fail right now. I just made GenericError to catch a few other kinds, if we like the way this proposal is going, I can do the work to figure out a better name, and/or break it up into two or three other kinds of errors. I’m not 100% sure how detailed we care to get here.
semver::range
range is a module imported from Cargo. @wycats supported the idea of pulling this out of Cargo and into SemVer. I’m calling it ‘range’ because it supports version ranges, but given that the only public thing in it is a VersionReq, maybe that would be a better name.
Also, VersionReq might be better as a VersionRequirement. That’s getting a bit long, though…
A VersionReq has no public fields, but some methods:
fn any() -> VersionReq
This produces a VersionReq that matches any other VersionReq, which is useful in many cases.
fn parse(input: &str) -> Result<VersionReq, String>
This is the equivalent of version::parse. I’m now noticing that this returns a String, maybe it should also be an enum. That this is a method might support turning version::parse into a method as well, or maybe the reverse.
fn exact(version: &Version) -> VersionReq
This checks to see if a VersionReq matches a Version exactly. Maybe this should be VersionReq == Version? Can that be done?
fn matches(&self, version: &Version) -> bool
This is the general match function, to see if a Version matches the range.
So, still some questions, but progress!