Skip to content

Commit b999b7d

Browse files
committed
Make port: None equal to port: default_port
Fix #132
1 parent a3cd772 commit b999b7d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ use std::fmt::{self, Formatter};
137137
use std::str;
138138
use std::path::{Path, PathBuf};
139139
use std::borrow::Borrow;
140+
use std::hash::{Hash, Hasher};
140141

141142
#[cfg(feature="serde_serialization")]
142143
use std::str::FromStr;
@@ -226,7 +227,7 @@ pub enum SchemeData {
226227
}
227228

228229
/// Components for URLs in a *relative* scheme such as HTTP.
229-
#[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
230+
#[derive(Clone, Debug, PartialOrd, Ord)]
230231
#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
231232
pub struct RelativeSchemeData {
232233
/// The username of the URL, as a possibly empty, percent-encoded string.
@@ -266,6 +267,33 @@ pub struct RelativeSchemeData {
266267
pub path: Vec<String>,
267268
}
268269

270+
impl RelativeSchemeData {
271+
fn get_identity_key(&self) -> (&String, &Option<String>, &Host, Option<u16>, Option<u16>, &Vec<String>) {
272+
(
273+
&self.username,
274+
&self.password,
275+
&self.host,
276+
self.port.or(self.default_port),
277+
self.default_port,
278+
&self.path
279+
)
280+
}
281+
}
282+
283+
284+
impl PartialEq for RelativeSchemeData {
285+
fn eq(&self, other: &RelativeSchemeData) -> bool {
286+
self.get_identity_key() == other.get_identity_key()
287+
}
288+
}
289+
290+
impl Eq for RelativeSchemeData {}
291+
292+
impl Hash for RelativeSchemeData {
293+
fn hash<H: Hasher>(&self, state: &mut H) {
294+
self.get_identity_key().hash(state)
295+
}
296+
}
269297

270298
impl str::FromStr for Url {
271299
type Err = ParseError;

0 commit comments

Comments
 (0)