Commit bd27ecfa authored by Scott Abbey's avatar Scott Abbey

Introduce parse_meta and Identifier for metadata strings

parent 1d96fcf6
......@@ -52,8 +52,16 @@ pub struct Version {
pub major: u64,
pub minor: u64,
pub patch: u64,
pub pre: Option<Vec<String>>,
pub build: Option<Vec<String>>,
pub pre: Option<Vec<Identifier>>,
pub build: Option<Vec<Identifier>>,
pub enum Identifier {
/// An identifier that's solely numbers.
/// An identifier with letters and numbers.
pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
......@@ -62,13 +70,9 @@ pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
None => return Err(From::from("Version did not parse properly.")),
let pre ="pre").map(|pre| {
let pre ="pre").map(parse_meta);
let build ="build").map(|build| {
let build ="build").map(parse_meta);
Ok(Version {
......@@ -79,6 +83,26 @@ pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
// by the time we get here, we know that it's all valid characters, so this doesn't need to return
// a result or anything
fn parse_meta(pre: &str) -> Vec<Identifier> {
// Originally, I wanted to implement this method via calling parse, but parse is tolerant of
// leading zeroes, and we want anything with leading zeroes to be considered alphanumeric, not
// numeric. So the strategy is to check with a regex first, and then call parse once we've
// determined that it's a number without a leading zero.
let regex = Regex::new(r"^[1-9][0-9]*$").unwrap();
.map(|part| {
if regex.is_match(part) {
// we can unwrap here because we know it is only digits due to the regex
} else {
mod tests {
use super::*;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment