Skip to content
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 (de)serialization of internal representation, to avoid re-parsing #259

Merged
merged 2 commits into from
Jan 23, 2017

Conversation

SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Dec 19, 2016

 + random drive-by fixes.

The trick used here to avoid a complex Deserialize impl (either hand-written on in a cumbersome generated file) is to use existing impls, namely those of Option and IpAddr.

@Manishearth, another change from your PR is checking invariants unconditionally (including release mode) so there there is no need for separate (de)serialize_unsafe methods. Does this run-time cost sound acceptable?

r? @Manishearth


This change is Reviewable

@erickt
Copy link

erickt commented Dec 19, 2016

Looks good to me from the serde angle.

@bors-servo
Copy link
Contributor

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

@Manishearth
Copy link
Member

so there there is no need for separate (de)serialize_unsafe methods. Does this run-time cost sound acceptable?

@nox disagrees. I am okay with this situation, sort of.

@Manishearth
Copy link
Member

r+ otherwise. Good idea.

@nox
Copy link
Contributor

nox commented Dec 19, 2016

I asked for separate methods because otherwise rust-url becomes pretty much useless to deserialize from JSON or TOML in the wild, where no one cares about the internal representation in rust-url.
Edit: and also because in these contexts, I wouldn't trust that not checking invariants and for normalisation have no security implications for some systems etc.

@SimonSapin
Copy link
Member Author

IMO serde::Serialize and serde::Deserialize should be used together. By "in the wild", I assume you mean a situation whene one of the two ends is not serde. In these situations, Url::as_str and Url::parse should be used instead.

@nox
Copy link
Contributor

nox commented Dec 19, 2016

What do you mean? Many people use serde to serialise configuration and whatnot. Our serde support ought to serialise as values which make sense in most contexts of serde. The internal representation isn't one of them. What about formats which don't even have a serialiser?

Also, this is a breaking change.

@SimonSapin SimonSapin changed the title Serde: serialize internal representation to avoid re-parsing. Add (de)serialization of internal representation, to avoid re-parsing Dec 19, 2016
@SimonSapin
Copy link
Member Author

Alright, I’ve changed the PR to leave the existing impls alone and add new inherent methods instead. r? @nox

@@ -38,4 +39,4 @@ heapsize = {version = ">=0.1.1, <0.4", optional = true}
idna = { version = "0.1.0", path = "./idna" }
matches = "0.1"
rustc-serialize = {version = "0.3", optional = true}
serde = {version = ">=0.6.1, <0.9", optional = true}
serde = {version = "0.8.20", optional = true}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nox correctly points out that this is a breaking change. @Manishearth why this change? Can we do without it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because bincode needs 0.8.20 and cargo isn't smart enough to coalesce the versions in a test-only dependency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use JSON instead for the test and revert this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead

@SimonSapin
Copy link
Member Author

@bors-servo r=Manishearth

@bors-servo
Copy link
Contributor

📌 Commit 5f5b943 has been approved by Manishearth

@bors-servo
Copy link
Contributor

⌛ Testing commit 5f5b943 with merge c0065ff...

bors-servo pushed a commit that referenced this pull request Jan 23, 2017
Add (de)serialization of internal representation, to avoid re-parsing

 + random drive-by fixes.

The trick used here to avoid a complex `Deserialize` impl (either hand-written on in a cumbersome generated file) is to use existing impls, namely those of `Option` and `IpAddr`.

@Manishearth, another change from your PR is checking invariants unconditionally (including release mode) so there there is no need for separate `(de)serialize_unsafe` methods. Does this run-time cost sound acceptable?

r? @Manishearth

<!-- 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/259)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit 5f5b943 into master Jan 23, 2017
@SimonSapin SimonSapin deleted the serde-as-internal branch January 23, 2017 18:02
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.

5 participants