You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #433 - dekellum:improve-violations-interface-2, r=nox
Improve syntax violations interface and preserve Copy
This is an alternative implementation of #430 which avoids introducing an `Rc<Fn>` and preserves `Copy` for `ParseOptions`. Thus, based on my current understanding with the prior review, it is completely backward compatible and with no breaking changes. Its a little less elegant in that, without the `Rc<Fn>`, I can not simple wrap the deprecated log_syntax_violation Fn with an adapting closure. But by moving the two possible function references into a new enum `ViolationFn` it is reasonably well contained. The interface for users is effectively the same, so I think the backward compatibility advantage makes this preferable to #430. Updated summary:
### Summary of changes
This makes programmatic use of syntax violations more practical while further centralizing this concern in the parser, which should be a maintenance win.
* New `SyntaxViolation` enum with descriptions the same as the prior violation static strings. This enables programmatic use of these violations by variant, e.g. ignoring some, warning on others, providing translated descriptions, etc. Enum implementation uses the same macro expansion pattern as was used for `ParseError`.
* New `syntax_violation_callback` signature in `ParseOptions` and `Parser`.
* Deprecated `log_syntax_violation` and re-implemented, passing the same violation descriptions for backward compatibility.
* Unit tests for old `log_syntax_violation` compatibility, and new `syntax_violation_callback`
* Includes rustdoc for old and new interfaces including tested example usage of new callback, as requested in #308.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/433)
<!-- Reviewable:end -->
0 commit comments