Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

seanmonstar
Copy link
Contributor

@seanmonstar seanmonstar commented May 22, 2017

  • I arbitrarily chose percent_encode, but I could update it to be percent_encoding if preferred.
  • The macro define_encode_set duplicated, to maintain backwards compatibility for url.
  • I set it 1.0.0 since this is a public dependency of url, and so it can't make API breaking changes easily without affecting url.

This change is Reviewable

@seanmonstar seanmonstar requested a review from nox May 26, 2017 19:30
Copy link
Contributor

@nox nox left a 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.

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] | {' ', '"', '#', '<', '>'}
}
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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;.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -0,0 +1,21 @@
[package]
name = "percent_encode"
Copy link
Contributor

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.

Copy link
Contributor

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.

@SimonSapin
Copy link
Member

I arbitrarily chose percent_encode, but I could update it to be percent_encoding if preferred.

I’m kind of splitting hairs, but I’d prefer percent_encoding. I think "encoding" refers to the general mechanism, which includes two opposite operations: "encode" and "decode".

@seanmonstar
Copy link
Contributor Author

Renamed to percent_encoding, stray code in url_serde removed.

@seanmonstar
Copy link
Contributor Author

@SimonSapin or @nox, r?

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #335) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo pushed a commit that referenced this pull request Jun 13, 2017
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 -->
@SimonSapin
Copy link
Member

Landed in #362. Thanks!

@seanmonstar seanmonstar deleted the percent-encode branch June 13, 2017 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants