Span-based email validation #272
Closed
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.
Hello folks, I've been working on a command-line library that uses
validatorto report errors in arguments, and have recently focused on improving the quality of reported error messages. For the invalid emailtest@"example.com, instead of:I would like to report something like:
To facilitate this, I have created a new function,
validate_email_span, that should behave exactly the same asvalidate_emailexcept instead of returning abool, it returns aResultwith additional context; an error enum and span for the first error encountered in the email.I understand such code may be out of scope for this library, but thought it would be worth sending a patch upstream before considering a different crate - this one is quite nice! This new function, and its supporting types, have been placed inside a
spanmodule. If such contributions are in scope I would like to explore adding more contextual validators, such as IP addresses.If there's anything I can do to ease the review process please let me know :)