-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved parser & diagnostics #560
Improved parser & diagnostics #560
Conversation
Would love to see the benchmarks on this |
I'm not sure how to benchmark, but the implementation is a slightly modified version of the |
I think @kinggoesgaming would be interested in the difference with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @QnnOkabayashi! This looks good to me 🚀
Yup this is exactly what I was thinking about. The couple of regressions are IMHO acceptable |
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