Skip to content
Properly parse prerelease and build tags

Time to fix the types on our prerelease and build tags.  Instead of just
reading the whole thing into a string, we will break them apart on
periods into either alphanumeric or numeric identifiers.

src/version.rs
--------------

Semver's prerelease and build tag [specification][0] describes tags as
either alphanumeric or numeric.  Instead of using the type
`Option<Vec<String>>` for the `pre` and `build` fields, let's create the
`Identifier` enum.  Identifiers may be either `AlphaNumeric` or
`Numeric`.

Note that we removed the `Option` around the type of `pre` and `build`.
Our tests expect just `Vec<Identifier>`, so we will return an empty
vector if nothing is present, rather than a `None`.  The
`unwrap_or(vec![])` on the lines assigning `pre` and `build` assigns
them empty vectors when no match was found.

Since we have to parse out the metadata twice, we'll use the
`parse_meta` function.  The operation is fairly straightforward. Just
split on periods. If all the characters in the string are digits, call
it a Numeric, otherwise call it AlphaNumeric.

[0]: http://semver.org/#spec-item-9