-
Notifications
You must be signed in to change notification settings - Fork 346
move percent_encoding to its own crate #347
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
Conversation
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.
Good stuff, few comments.
url_serde/src/lib.rs
Outdated
define_encode_set! { | ||
/// This encode set is used in the URL parser for query strings. | ||
pub QUERY_ENCODE_SET = [::url::percent_encoding::SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'} | ||
} |
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.
Why does this need to be done here?
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.
Um, I have no idea why this is here...
/// # } | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! define_encode_set { |
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.
Isn't there a way to reexport a macro from a different crate?
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.
IIRC the only way on current stable Rust is pub use some_crate::*;
, which of course also re-exports other things.
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.
There's #[macro_reexport]
, which is unstable, and there's a the glob trick, which I'm still not certain is on purpose, but still, it re-exports too many things, so duplicating the macro seems required...
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.
@nox you said in IRC you prefer the glob trick. To reiterate, that requires a pub use percent_encoding::*
inside the url
root. That would suddenly make all the things normally in that module/crate pollute the url namespace. Suddenly there is url::SIMPLE_ENCODE_SET
, besides url::percent_encoding::SIMPLE_ENCODE_SET
and friends.
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.
Can't you just put the macro in a submodule of percent_encoding
and glob import that module from both percent_encoding
and url
?
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.
That's possible, but puts another public (useless) module in the percent_encoding
crate. Of all the possible options, I find just redefining the macro in url
to be the best.
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.
Given both crates are in the same repository, IMO it is better to just make a #[doc(hidden)]
module and avoid the duplication of the macro, but I'll let @SimonSapin the final say.
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.
When macros 2.0 arrive (already major pieces in nightly!), they can be named explicit, so it could eventually just become in url pub use percent_encoding::define_encode_set;
.
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.
Unfortunately I don't think these two crates can really afford to rely on hot new stuff, given how central it is to the ecosystem.
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.
We can cross that bridge when we get there, but this crate has already made upgrades to 1.15, and other than using the newest the day after, it seems to be fine to upgrade to newer version.
percent_encode/Cargo.toml
Outdated
@@ -0,0 +1,21 @@ | |||
[package] | |||
name = "percent_encode" |
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.
I'll let @SimonSapin decide on the crate name.
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.
11:10 <•SimonSapin> nox: if we’re splitting hairs, I think "encoding" is the general mechanism and the two specific (opposite) operations are "encode" and "decode"
Let's name it percent_encoding
.
I’m kind of splitting hairs, but I’d prefer |
a40b2d2
to
31c6f04
Compare
Renamed to |
@SimonSapin or @nox, r? |
☔ The latest upstream changes (presumably #335) made this pull request unmergeable. Please resolve the merge conflicts. |
Move percent encoding to its own crate This is a rebase of #347 with some additional changes. Original work by @seanmonstar. Fixes #347. <!-- 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/362) <!-- Reviewable:end -->
Landed in #362. Thanks! |
percent_encode
, but I could update it to bepercent_encoding
if preferred.define_encode_set
duplicated, to maintain backwards compatibility forurl
.url
, and so it can't make API breaking changes easily without affectingurl
.This change is