diff --git a/src/lib.rs b/src/lib.rs index 348bbf94a..27f29d7ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -841,6 +841,7 @@ impl Uuid { expected: "0123456789abcdefABCDEF-", found: input[i_char..].chars().next().unwrap(), index: i_char, + urn: parser::UrnPrefix::Optional, }); } } @@ -875,6 +876,7 @@ impl Uuid { expected: "0123456789abcdefABCDEF-", found: input[i_char..].chars().next().unwrap(), index: i_char, + urn: parser::UrnPrefix::Optional, }); } } @@ -1066,6 +1068,7 @@ mod tests { expected: EXPECTED_CHARS, found: 'G', index: 20, + urn: parser::UrnPrefix::Optional, }) ); @@ -1107,6 +1110,7 @@ mod tests { expected: EXPECTED_CHARS, found: 'X', index: 18, + urn: parser::UrnPrefix::Optional, }) ); @@ -1159,6 +1163,7 @@ mod tests { expected: EXPECTED_CHARS, found: '%', index: 15, + urn: parser::UrnPrefix::Optional, }) ); @@ -1212,6 +1217,7 @@ mod tests { expected: EXPECTED_CHARS, found: 'X', index: 6, + urn: parser::UrnPrefix::Optional, }) ); assert_eq!( diff --git a/src/parser/core_support.rs b/src/parser/core_support.rs index ca6e8ded8..971581b4f 100644 --- a/src/parser/core_support.rs +++ b/src/parser/core_support.rs @@ -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, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index edd959d5e..2b4d62bb4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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 @@ -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. ///