Improved parser & diagnostics #560
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm submitting a feature
Description
This features adds drastically improved diagnostics for error handling for the
uuid!()
macro. Improvements include not panicking on multibyte characters, and providing more human-oriented feedback on why a string failed to parse. For example, instead of complaining about an invalid length if the last group has one too many characters, it will tell you that the last group has one too many characters.This PR also improves the parser implementation. It works by separating the parsing from error handling, allowing the parser to be a
const
fn that is heavily optimized and returnsOption<[u8; 16]>
, where the error handler can come along later and figure out exactly what went wrong if the user cares. This is because most of the time, it's likely that the user doesn't particularly care what went wrong because they aren't expecting it to fail.Finally, it introduces the
Uuid::try_parse
method, which is intended to replaceUuid::parse_str
. They do the same thing, exceptUuid::parse_str
will automatically diagnose the error with slight overhead in the case that it fails, whereUuid::try_parse
just returns the lightweight error type,InvalidUuid
, that can be diagnosed at a later time usingInvalidUuid::into_err
.Related Issue(s)
#559
#556