Skip to content

Implement Hash for Origin (fix #302) #321

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

Merged
merged 1 commit into from
Jun 3, 2017
Merged

Implement Hash for Origin (fix #302) #321

merged 1 commit into from
Jun 3, 2017

Conversation

cGuille
Copy link
Contributor

@cGuille cGuille commented May 5, 2017

Hello,

I'm a Rust / Open Source beginner, so just explain if anything is wrong. :-)

I am giving a try at issue #302. I just derived the Hash for the Origin type.

I have zero experience with testing in Rust so I just tried to demonstrate that it works, but I do not know how to write a good test for this.

What should I do now?


This change is Reviewable

@skade
Copy link

skade commented May 5, 2017

@cGuille Wait for one of the maintainers to provide review :). Most maintainers of the URL crate live in the US, so this might take until later.

Ignore the nightly error in the linked travis test suite, rust nightly is currently broken, not this lib.

@emilio
Copy link
Member

emilio commented May 5, 2017

@SimonSapin is french fwiw, hopefully he can take a look soon-ish.

Can you test also that opaque origins get different hashes? (It's trivial, but worth having that in the test-suite too).

@cGuille
Copy link
Contributor Author

cGuille commented May 5, 2017

Hello,

There is actually no hurry at all. :-)

I am OK with adding more tests ; I will just have to figure out how.
I do not like using HashMap to indirectly test the Hash trait ; it would be nice to have someone else's opinion about this.

@SimonSapin
Copy link
Member

@skade, unfortunately, most of the maintainers of the url crate are me :) I’m usually in UTC+1~2.

@cGuille You can hash without a hashmap like so:

use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;

fn hash<T: Hash>(value: T) -> u64 {
    let mut hasher = DefaultHasher::new();
    value.hash(&mut hasher);
    hasher.finish()
}

To make the test more interesting, you could use different URLs that have the same origin. Please also test that hashing is consistent with == equality.

Thanks!

@cGuille
Copy link
Contributor Author

cGuille commented May 5, 2017

Thank you!

I updated the PR to test hash values directly instead of using HashMap, but I do not know how to test that hashing is consistent with equality. Do you have something in mind?
Should I just check that equalities of the origins in my test are the same as the equalities of their hashes?

@SimonSapin
Copy link
Member

Test that things that compare equal with == have the same hash. Test that things that compare unequal have a different hash. The latter is not guaranteed because there could be hashing collisions, but it is unlikely enough that it’s alright to test in a couple fixed-input test cases.

@cGuille
Copy link
Contributor Author

cGuille commented May 5, 2017

What do you think about this? Are there enough URL samples?
Edit: I also added tests with opaque origins, as @emilio suggested.

@bors-servo
Copy link
Contributor

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

@cGuille
Copy link
Contributor Author

cGuille commented May 10, 2017

I solved the conflict with master and rebased the branch upon it.

Tell me if there is anything left to do regarding this PR.

Copy link
Contributor

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Looks good to me. All of the feedback so far has been addressed.

@bors-servo
Copy link
Contributor

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

@cGuille
Copy link
Contributor Author

cGuille commented May 26, 2017

I rebased upon master to solve this second conflict.

Can this be merged?

@cGuille
Copy link
Contributor Author

cGuille commented May 29, 2017

@bors-servo r? @SimonSapin

@brson
Copy link
Contributor

brson commented Jun 3, 2017

@bors-servo r+

bors-servo probably doesn't listen to me...

@bors-servo
Copy link
Contributor

@brson: 🔑 Insufficient privileges: Not in reviewers

@brson
Copy link
Contributor

brson commented Jun 3, 2017

Sorry for the delay @cGuille !

@cbrewster
Copy link
Contributor

@bors-servo r=brson

@bors-servo
Copy link
Contributor

📌 Commit 4260325 has been approved by brson

@bors-servo
Copy link
Contributor

⌛ Testing commit 4260325 with merge 2641e36...

bors-servo pushed a commit that referenced this pull request Jun 3, 2017
Implement `Hash` for `Origin` (fix #302)

Hello,

I'm a Rust / Open Source beginner, so just explain if anything is wrong. :-)

I am giving a try at issue #302. I just derived the `Hash` for the `Origin` type.

I have zero experience with testing in Rust so I just tried to demonstrate that it works, but I do not know how to write a good test for this.

What should I do now?

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

☀️ Test successful - status-travis
Approved by: brson
Pushing 2641e36 to master...

@bors-servo bors-servo merged commit 4260325 into servo:master Jun 3, 2017
@cGuille cGuille deleted the impl-hash-trait-for-origin branch July 3, 2017 12:42
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.

8 participants