-
Notifications
You must be signed in to change notification settings - Fork 333
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
Add examples to ParseOptions
#308
Comments
A base URL has nothing to do with performance. It is required to resolve relative URL references like
Since |
Hello @brson I would like to contribute with this =D |
Thanks @marti1125! Let us know here or in the #servo IRC channel if you need any clarification. |
@marti1125 Awesome! I saw you pinged my on IRC today. Sorry I missed you. IRC is the best way to get ahold of me usually, though note I'll be on vacation next week. Please work with @dtolnay. |
ok =D @dtolnay what is you nick at irc ? |
dtolnay |
at #servo ? I don't find you =( |
@marti1125 no you can find @dtolnay on #rust-libs though. |
@SimonSapin Can we talk at irc for fix this issue ? my nick is marti_ |
Hi, I'm (mostly) successfully using log_syntax_violation in some crawling-related code of my own, so I can offer a (perhaps unexpected) usage example and some usage feedback which I hope you will consider. I'm normalizing/validating URLs beyond what is strictly required by the spec, and in some cases this means wanting to promote a syntax violation warning to an Error result for filtering purposes. To work within the /// Parse raw_url with optional base using parse options to get the
/// last syntax violation, if any.
fn parse_v(base: Option<&Url>, raw_url: &str)
-> Result<(Url,Option<String>)>
{
let violation: Cell<Option<String>> = Cell::new(None);
let url = {
let vfn = & |s: &str| {
violation.set(Some(s.to_owned()));
};
let options = Url::options().
log_syntax_violation(Some(vfn)).
base_url(base);
options.parse(raw_url)
}?;
Ok((url,violation.into_inner()))
} So I could extract and PR doc example from this if desired? Usage feedback:
fn parse_with_violations(input: &str) -> Result<(Url,Vec<Violation>), ParseError> Its all related, but let me know if any of this would be better in its own issue and I can create it. Thanks for your efforts! |
@dekellum You might be the first to actually use A dedicated method goes against the idea of the |
Thanks @SimonSapin. I understand the builder pattern. I was only looking for a way around the awkward Could you/someone offer hope that a PR would be considered, if I attempted to improve the general form and flexibility of this syntax violation feature? Not much risk of breakage, if I'm the only one using it? Right? :) |
Enable rustdoc for feature query_encoding on docs.rs So that ParseOptions::encoding_override shows up on docs.rs This relates to and was requested by me in #308. I believe this is how to implement. See onur/docs.rs@62fdcf605 for the docs.rs support of this config. <!-- 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/427) <!-- Reviewable:end -->
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 -->
Closing as fixed, thanks @dekellum. |
And an explanation of why you would use it. Seems like it's mostly for hooking into parse warnings with
log_syntax_violation
. Not sure whatbase_url
would be used for - some performance optimization? Ask on #servo.Might want to do this as the same time as #301
The text was updated successfully, but these errors were encountered: