Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ impl<T> HeaderMap<T> {
#[inline]
fn find<K>(&self, key: &K) -> Option<(usize, usize)>
where
K: Hash + Into<HeaderName> + ?Sized,
K: Hash + Into<HeaderName>,
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed? It's been a long time since I've looked at this, wasn't it necessary to allow K = str?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that K is required to be Sized since Into requires Sized.

HeaderName: PartialEq<K>,
{
if self.entries.is_empty() {
Expand Down Expand Up @@ -3758,7 +3758,7 @@ mod into_header_name {

impl IntoHeaderName for HeaderName {}

impl<'a> Sealed for &'a HeaderName {
impl Sealed for &HeaderName {
#[inline]
fn try_insert<T>(
self,
Expand All @@ -3778,7 +3778,7 @@ mod into_header_name {
}
}

impl<'a> IntoHeaderName for &'a HeaderName {}
impl IntoHeaderName for &HeaderName {}

impl Sealed for &'static str {
#[inline]
Expand Down Expand Up @@ -3868,7 +3868,7 @@ mod as_header_name {

impl AsHeaderName for HeaderName {}

impl<'a> Sealed for &'a HeaderName {
impl Sealed for &HeaderName {
#[inline]
fn try_entry<T>(self, map: &mut HeaderMap<T>) -> Result<Entry<'_, T>, TryEntryError> {
Ok(map.try_entry2(self)?)
Expand All @@ -3884,9 +3884,9 @@ mod as_header_name {
}
}

impl<'a> AsHeaderName for &'a HeaderName {}
impl AsHeaderName for &HeaderName {}

impl<'a> Sealed for &'a str {
impl Sealed for &str {
#[inline]
fn try_entry<T>(self, map: &mut HeaderMap<T>) -> Result<Entry<'_, T>, TryEntryError> {
Ok(HdrName::from_bytes(self.as_bytes(), move |hdr| {
Expand All @@ -3904,7 +3904,7 @@ mod as_header_name {
}
}

impl<'a> AsHeaderName for &'a str {}
impl AsHeaderName for &str {}

impl Sealed for String {
#[inline]
Expand All @@ -3924,7 +3924,7 @@ mod as_header_name {

impl AsHeaderName for String {}

impl<'a> Sealed for &'a String {
impl Sealed for &String {
#[inline]
fn try_entry<T>(self, map: &mut HeaderMap<T>) -> Result<Entry<'_, T>, TryEntryError> {
self.as_str().try_entry(map)
Expand All @@ -3940,7 +3940,7 @@ mod as_header_name {
}
}

impl<'a> AsHeaderName for &'a String {}
impl AsHeaderName for &String {}
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/header/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ impl<'a> PartialEq<&'a HeaderName> for HeaderName {
}
}

impl<'a> PartialEq<HeaderName> for &'a HeaderName {
impl PartialEq<HeaderName> for &HeaderName {
#[inline]
fn eq(&self, other: &HeaderName) -> bool {
*other == *self
Expand Down Expand Up @@ -1466,7 +1466,7 @@ impl<'a> PartialEq<&'a str> for HeaderName {
}
}

impl<'a> PartialEq<HeaderName> for &'a str {
impl PartialEq<HeaderName> for &str {
/// Performs a case-insensitive comparison of the string against the header
/// name
#[inline]
Expand Down
12 changes: 6 additions & 6 deletions src/header/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ macro_rules! from_integers {
let val = HeaderValue::from(n);
assert_eq!(val, &n.to_string());

let n = ::std::$t::MAX;
let n = $t::MAX;
let val = HeaderValue::from(n);
assert_eq!(val, &n.to_string());
}
Expand Down Expand Up @@ -543,7 +543,7 @@ mod try_from_header_name_tests {
#[test]
fn it_converts_using_try_from() {
assert_eq!(
HeaderValue::try_from(name::UPGRADE).unwrap(),
HeaderValue::from(name::UPGRADE),
HeaderValue::from_bytes(b"upgrade").unwrap()
);
}
Expand Down Expand Up @@ -697,14 +697,14 @@ impl PartialOrd<HeaderValue> for String {
}
}

impl<'a> PartialEq<HeaderValue> for &'a HeaderValue {
impl PartialEq<HeaderValue> for &HeaderValue {
#[inline]
fn eq(&self, other: &HeaderValue) -> bool {
**self == *other
}
}

impl<'a> PartialOrd<HeaderValue> for &'a HeaderValue {
impl PartialOrd<HeaderValue> for &HeaderValue {
#[inline]
fn partial_cmp(&self, other: &HeaderValue) -> Option<cmp::Ordering> {
(**self).partial_cmp(other)
Expand All @@ -731,14 +731,14 @@ where
}
}

impl<'a> PartialEq<HeaderValue> for &'a str {
impl PartialEq<HeaderValue> for &str {
#[inline]
fn eq(&self, other: &HeaderValue) -> bool {
*other == *self
}
}

impl<'a> PartialOrd<HeaderValue> for &'a str {
impl PartialOrd<HeaderValue> for &str {
#[inline]
fn partial_cmp(&self, other: &HeaderValue) -> Option<cmp::Ordering> {
self.as_bytes().partial_cmp(other.as_bytes())
Expand Down
4 changes: 2 additions & 2 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'a> PartialEq<&'a Method> for Method {
}
}

impl<'a> PartialEq<Method> for &'a Method {
impl PartialEq<Method> for &Method {
#[inline]
fn eq(&self, other: &Method) -> bool {
*self == other
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'a> PartialEq<&'a str> for Method {
}
}

impl<'a> PartialEq<Method> for &'a str {
impl PartialEq<Method> for &str {
#[inline]
fn eq(&self, other: &Method) -> bool {
*self == other.as_ref()
Expand Down
12 changes: 6 additions & 6 deletions src/uri/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl PartialEq<Authority> for str {
}
}

impl<'a> PartialEq<Authority> for &'a str {
impl PartialEq<Authority> for &str {
fn eq(&self, other: &Authority) -> bool {
self.eq_ignore_ascii_case(other.as_str())
}
Expand Down Expand Up @@ -302,7 +302,7 @@ impl PartialOrd<Authority> for str {
}
}

impl<'a> PartialOrd<Authority> for &'a str {
impl PartialOrd<Authority> for &str {
fn partial_cmp(&self, other: &Authority) -> Option<cmp::Ordering> {
let left = self.as_bytes().iter().map(|b| b.to_ascii_lowercase());
let right = other.data.as_bytes().iter().map(|b| b.to_ascii_lowercase());
Expand Down Expand Up @@ -660,10 +660,10 @@ mod tests {
#[test]
fn compares_with_a_string() {
let authority: Authority = "def.com".parse().unwrap();
assert!(authority < "ghi.com".to_string());
assert!("ghi.com".to_string() > authority);
assert!(authority > "abc.com".to_string());
assert!("abc.com".to_string() < authority);
assert!(authority < "ghi.com");
assert!("ghi.com" > authority);
assert!(authority > "abc.com");
assert!("abc.com" < authority);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl<'a> PartialEq<&'a str> for Uri {
}
}

impl<'a> PartialEq<Uri> for &'a str {
impl PartialEq<Uri> for &str {
fn eq(&self, uri: &Uri) -> bool {
uri == *self
}
Expand Down
14 changes: 7 additions & 7 deletions src/uri/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl PartialEq<str> for PathAndQuery {
}
}

impl<'a> PartialEq<PathAndQuery> for &'a str {
impl PartialEq<PathAndQuery> for &str {
#[inline]
fn eq(&self, other: &PathAndQuery) -> bool {
self == &other.as_str()
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'a> PartialOrd<&'a str> for PathAndQuery {
}
}

impl<'a> PartialOrd<PathAndQuery> for &'a str {
impl PartialOrd<PathAndQuery> for &str {
#[inline]
fn partial_cmp(&self, other: &PathAndQuery) -> Option<cmp::Ordering> {
self.partial_cmp(&other.as_str())
Expand Down Expand Up @@ -620,10 +620,10 @@ mod tests {
#[test]
fn compares_with_a_string() {
let path_and_query: PathAndQuery = "/b/world&foo=bar".parse().unwrap();
assert!(path_and_query < "/c/world&foo=bar".to_string());
assert!("/c/world&foo=bar".to_string() > path_and_query);
assert!(path_and_query > "/a/world&foo=bar".to_string());
assert!("/a/world&foo=bar".to_string() < path_and_query);
assert!(path_and_query < "/c/world&foo=bar");
assert!("/c/world&foo=bar" > path_and_query);
assert!(path_and_query > "/a/world&foo=bar");
assert!("/a/world&foo=bar" < path_and_query);
}

#[test]
Expand Down Expand Up @@ -671,6 +671,6 @@ mod tests {
}

fn pq(s: &str) -> PathAndQuery {
s.parse().expect(&format!("parsing {}", s))
s.parse().unwrap_or_else(|_| panic!("parsing {s}"))
}
}
2 changes: 1 addition & 1 deletion src/uri/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,6 @@ mod test {
}

fn scheme(s: &str) -> Scheme {
s.parse().expect(&format!("Invalid scheme: {}", s))
s.parse().unwrap_or_else(|_| panic!("Invalid scheme: {s}"))
}
}
2 changes: 1 addition & 1 deletion tests/header_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn with_capacity_overflow() {
fn reserve_overflow() {
// See https://github.com/hyperium/http/issues/352
let mut headers = HeaderMap::<u32>::with_capacity(0);
headers.reserve(std::usize::MAX); // next_power_of_two overflows
headers.reserve(usize::MAX); // next_power_of_two overflows
}

#[test]
Expand Down