Skip to content

Commit

Permalink
Merge #397
Browse files Browse the repository at this point in the history
397: adjust ParseError for indicating if an urn format was expected r=Dylan-DPC a=kinggoesgaming

**I'm submitting a(n)** refactor

# Description
Allows for future parsing ability for the adapters.

# Motivation
This was a breaking change as such was needed to be added in 0.8.0`

# Tests
Current tests should pass. No new tests introduced.

# Related Issue(s)
closes #370 


Co-authored-by: Hunar Roop Kahlon <[email protected]>
  • Loading branch information
bors[bot] and kinggoesgaming committed Apr 18, 2019
2 parents 237efb1 + 9182349 commit 2d91636
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ impl Uuid {
expected: "0123456789abcdefABCDEF-",
found: input[i_char..].chars().next().unwrap(),
index: i_char,
urn: parser::UrnPrefix::Optional,
});
}
}
Expand Down Expand Up @@ -875,6 +876,7 @@ impl Uuid {
expected: "0123456789abcdefABCDEF-",
found: input[i_char..].chars().next().unwrap(),
index: i_char,
urn: parser::UrnPrefix::Optional,
});
}
}
Expand Down Expand Up @@ -1066,6 +1068,7 @@ mod tests {
expected: EXPECTED_CHARS,
found: 'G',
index: 20,
urn: parser::UrnPrefix::Optional,
})
);

Expand Down Expand Up @@ -1107,6 +1110,7 @@ mod tests {
expected: EXPECTED_CHARS,
found: 'X',
index: 18,
urn: parser::UrnPrefix::Optional,
})
);

Expand Down Expand Up @@ -1159,6 +1163,7 @@ mod tests {
expected: EXPECTED_CHARS,
found: '%',
index: 15,
urn: parser::UrnPrefix::Optional,
})
);

Expand Down Expand Up @@ -1212,6 +1217,7 @@ mod tests {
expected: EXPECTED_CHARS,
found: 'X',
index: 6,
urn: parser::UrnPrefix::Optional,
})
);
assert_eq!(
Expand Down
17 changes: 16 additions & 1 deletion src/parser/core_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,23 @@ impl fmt::Display for parser::ParseError {
expected,
found,
index,
urn,
} => {
write!(f, "expected {}, found {} at {}", expected, found, index)
let urn_str = match urn {
parser::UrnPrefix::None => "",
parser::UrnPrefix::Optional => {
" an optional prefix of `urn:uuid:` followed by"
}
parser::UrnPrefix::Required => {
" a prefix of `urn:uuid` followed by"
}
};

write!(
f,
"expected{} {}, found {} at {}",
urn_str, expected, found, index
)
}
parser::ParseError::InvalidGroupCount {
ref expected,
Expand Down
17 changes: 17 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ pub enum Expected {
},
}

/// Urn prefix value.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum UrnPrefix {
/// No `urn:uuid:` prefix should be provided.
None,
/// The `urn:uuid:` prefix should optionally provided.
Optional,
/// The `urn:uuid:` prefix is required.
Required,
}

/// An error that can occur while parsing a [`Uuid`] string.
///
/// [`Uuid`]: ../struct.Uuid.html
Expand All @@ -48,6 +59,12 @@ pub enum ParseError {
found: char,
/// The invalid character position.
index: usize,
/// Indicates the [`Uuid`] starts with `urn:uuid:`.
///
/// This is a special case for [`Urn`] adapter parsing.
///
/// [`Uuid`]: ../Uuid.html
urn: UrnPrefix,
},
/// Invalid number of segments in the [`Uuid`] string.
///
Expand Down

0 comments on commit 2d91636

Please sign in to comment.