Skip to content

Commit

Permalink
run clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rodler committed Jun 8, 2023
1 parent 8e1b52e commit 9920187
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/byte_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ByteStr {
}
}
// Invariant: assumed by the safety requirements of this function.
ByteStr { bytes: bytes }
ByteStr { bytes }
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl<T> HeaderMap<T> {
assert!(cap <= MAX_SIZE, "header map reserve over max capacity");
assert!(cap != 0, "header map reserve overflowed");

if self.entries.len() == 0 {
if self.entries.is_empty() {
self.mask = cap as Size - 1;
self.indices = vec![Pos::none(); cap].into_boxed_slice();
self.entries = Vec::with_capacity(usable_capacity(cap));
Expand Down Expand Up @@ -1082,22 +1082,22 @@ impl<T> HeaderMap<T> {
danger,
Entry::Vacant(VacantEntry {
map: self,
hash: hash,
hash,
key: key.into(),
probe: probe,
danger: danger,
probe,
danger,
}),
Entry::Occupied(OccupiedEntry {
map: self,
index: pos,
probe: probe,
probe,
}),
Entry::Vacant(VacantEntry {
map: self,
hash: hash,
hash,
key: key.into(),
probe: probe,
danger: danger,
probe,
danger,
})
)
}
Expand Down Expand Up @@ -1201,7 +1201,7 @@ impl<T> HeaderMap<T> {

ValueDrain {
first: Some(old),
next: next,
next,
lt: PhantomData,
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ impl<T> HeaderMap<T> {

// backward shift deletion in self.indices
// after probe, shift all non-ideally placed indices backward
if self.entries.len() > 0 {
if !self.entries.is_empty() {
let mut last_probe = probe;
let mut probe = probe + 1;

Expand Down Expand Up @@ -1454,9 +1454,9 @@ impl<T> HeaderMap<T> {
assert!(self.entries.len() < MAX_SIZE, "header map at capacity");

self.entries.push(Bucket {
hash: hash,
key: key,
value: value,
hash,
key,
value,
links: None,
});
}
Expand Down Expand Up @@ -1851,7 +1851,7 @@ impl<'a, K, V, T> TryFrom<&'a HashMap<K, V>> for HeaderMap<T>
type Error = Error;

fn try_from(c: &'a HashMap<K, V>) -> Result<Self, Self::Error> {
c.into_iter()
c.iter()
.map(|(k, v)| -> crate::Result<(HeaderName, T)> {
let name = TryFrom::try_from(k).map_err(Into::into)?;
let value = TryFrom::try_from(v).map_err(Into::into)?;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ fn append_value<T>(
Some(links) => {
let idx = extra.len();
extra.push(ExtraValue {
value: value,
value,
prev: Link::Extra(links.tail),
next: Link::Entry(entry_idx),
});
Expand All @@ -2050,7 +2050,7 @@ fn append_value<T>(
None => {
let idx = extra.len();
extra.push(ExtraValue {
value: value,
value,
prev: Link::Entry(entry_idx),
next: Link::Entry(entry_idx),
});
Expand Down Expand Up @@ -2422,7 +2422,7 @@ impl<'a, T> VacantEntry<'a, T> {
// Ensure that there is space in the map
let index =
self.map
.insert_phase_two(self.key, value.into(), self.hash, self.probe, self.danger);
.insert_phase_two(self.key, value, self.hash, self.probe, self.danger);

&mut self.map.entries[index].value
}
Expand All @@ -2449,11 +2449,11 @@ impl<'a, T> VacantEntry<'a, T> {
// Ensure that there is space in the map
let index =
self.map
.insert_phase_two(self.key, value.into(), self.hash, self.probe, self.danger);
.insert_phase_two(self.key, value, self.hash, self.probe, self.danger);

OccupiedEntry {
map: self.map,
index: index,
index,
probe: self.probe,
}
}
Expand Down Expand Up @@ -2863,7 +2863,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
/// assert_eq!("earth", map["host"]);
/// ```
pub fn insert(&mut self, value: T) -> T {
self.map.insert_occupied(self.index, value.into())
self.map.insert_occupied(self.index, value)
}

/// Sets the value of the entry.
Expand All @@ -2889,7 +2889,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
/// assert_eq!("earth", map["host"]);
/// ```
pub fn insert_mult(&mut self, value: T) -> ValueDrain<'_, T> {
self.map.insert_occupied_mult(self.index, value.into())
self.map.insert_occupied_mult(self.index, value)
}

/// Insert the value into the entry.
Expand All @@ -2916,7 +2916,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
pub fn append(&mut self, value: T) {
let idx = self.index;
let entry = &mut self.map.entries[idx];
append_value(idx, entry, &mut self.map.extra_values, value.into());
append_value(idx, entry, &mut self.map.extra_values, value);
}

/// Remove the entry from the map.
Expand Down Expand Up @@ -3095,12 +3095,12 @@ impl<'a, T> Iterator for ValueDrain<'a, T> {
// Exactly 1
(&Some(_), &None) => (1, Some(1)),
// 1 + extras
(&Some(_), &Some(ref extras)) => {
(&Some(_), Some(extras)) => {
let (l, u) = extras.size_hint();
(l + 1, u.map(|u| u + 1))
},
// Extras only
(&None, &Some(ref extras)) => extras.size_hint(),
(&None, Some(extras)) => extras.size_hint(),
// No more
(&None, &None) => (0, Some(0)),
}
Expand All @@ -3111,7 +3111,7 @@ impl<'a, T> FusedIterator for ValueDrain<'a, T> {}

impl<'a, T> Drop for ValueDrain<'a, T> {
fn drop(&mut self) {
while let Some(_) = self.next() {}
for _ in self.by_ref() {}
}
}

Expand Down Expand Up @@ -3154,7 +3154,7 @@ impl Pos {
debug_assert!(index < MAX_SIZE);
Pos {
index: index as Size,
hash: hash,
hash,
}
}

Expand Down Expand Up @@ -3418,7 +3418,7 @@ mod as_header_name {
}

fn as_str(&self) -> &str {
<HeaderName>::as_str(*self)
<HeaderName>::as_str(self)
}
}

Expand Down Expand Up @@ -3472,7 +3472,7 @@ mod as_header_name {
}

fn as_str(&self) -> &str {
*self
self
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/header/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ impl HeaderName {
};
}

if name_bytes.len() == 0 || name_bytes.len() > super::MAX_HEADER_NAME_LEN || {
if name_bytes.is_empty() || name_bytes.len() > super::MAX_HEADER_NAME_LEN || {
let mut i = 0;
loop {
if i >= name_bytes.len() {
Expand All @@ -1283,7 +1283,7 @@ impl HeaderName {
pub fn as_str(&self) -> &str {
match self.inner {
Repr::Standard(v) => v.as_str(),
Repr::Custom(ref v) => &*v.0,
Repr::Custom(ref v) => &v.0,
}
}

Expand Down Expand Up @@ -1516,8 +1516,8 @@ impl<'a> HdrName<'a> {
HdrName {
// Invariant (on MaybeLower): follows from the precondition
inner: Repr::Custom(MaybeLower {
buf: buf,
lower: lower,
buf,
lower,
}),
}
}
Expand Down Expand Up @@ -1552,7 +1552,7 @@ impl<'a> From<HdrName<'a>> for HeaderName {
},
Repr::Custom(maybe_lower) => {
if maybe_lower.lower {
let buf = Bytes::copy_from_slice(&maybe_lower.buf[..]);
let buf = Bytes::copy_from_slice(maybe_lower.buf);
// Safety: the invariant on MaybeLower ensures buf is valid UTF-8.
let byte_str = unsafe { ByteStr::from_utf8_unchecked(buf) };

Expand Down
4 changes: 2 additions & 2 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ mod extension {
}

pub fn as_str(&self) -> &str {
// Safety: the invariant of AllocatedExtension ensures that self.0
// SAFETY: the invariant of AllocatedExtension ensures that self.0
// contains valid UTF-8.
unsafe {str::from_utf8_unchecked(&self.0)}
}
Expand Down Expand Up @@ -468,6 +468,6 @@ mod test {
assert_eq!(Method::from_str("wOw!!").unwrap(), "wOw!!");

let long_method = "This_is_a_very_long_method.It_is_valid_but_unlikely.";
assert_eq!(Method::from_str(&long_method).unwrap(), long_method);
assert_eq!(Method::from_str(long_method).unwrap(), long_method);
}
}
4 changes: 2 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<T> Request<T> {
pub fn new(body: T) -> Request<T> {
Request {
head: Parts::new(),
body: body,
body,
}
}

Expand All @@ -459,7 +459,7 @@ impl<T> Request<T> {
pub fn from_parts(parts: Parts, body: T) -> Request<T> {
Request {
head: parts,
body: body,
body,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<T> Response<T> {
pub fn new(body: T) -> Response<T> {
Response {
head: Parts::new(),
body: body,
body,
}
}

Expand All @@ -274,7 +274,7 @@ impl<T> Response<T> {
pub fn from_parts(parts: Parts, body: T) -> Response<T> {
Response {
head: parts,
body: body,
body,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl StatusCode {
/// ```
#[inline]
pub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode> {
if src < 100 || src >= 1000 {
if !(100..1000).contains(&src) {
return Err(InvalidStatusCode::new());
}

Expand Down Expand Up @@ -265,7 +265,7 @@ impl FromStr for StatusCode {
impl<'a> From<&'a StatusCode> for StatusCode {
#[inline]
fn from(t: &'a StatusCode) -> Self {
t.clone()
*t
}
}

Expand Down Expand Up @@ -544,7 +544,7 @@ impl Error for InvalidStatusCode {}

// A string of packed 3-ASCII-digit status code values for the supported range
// of [100, 999] (900 codes, 2700 bytes).
const CODE_DIGITS: &'static str = "\
const CODE_DIGITS: &str = "\
100101102103104105106107108109110111112113114115116117118119\
120121122123124125126127128129130131132133134135136137138139\
140141142143144145146147148149150151152153154155156157158159\
Expand Down
17 changes: 8 additions & 9 deletions src/uri/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Authority {
pub fn port(&self) -> Option<Port<&str>> {
let bytes = self.as_str();
bytes
.rfind(":")
.rfind(':')
.and_then(|i| Port::from_str(&bytes[i + 1..]).ok())
}

Expand All @@ -249,7 +249,7 @@ impl Authority {
/// assert_eq!(authority.port_u16(), Some(80));
/// ```
pub fn port_u16(&self) -> Option<u16> {
self.port().and_then(|p| Some(p.as_u16()))
self.port().map(|p| p.as_u16())
}

/// Return a str representation of the authority
Expand Down Expand Up @@ -430,7 +430,7 @@ impl<'a> TryFrom<&'a [u8]> for Authority {

// Preconditon on create_authority: copy_from_slice() copies all of
// bytes from the [u8] parameter into a new Bytes
create_authority(s, |s| Bytes::copy_from_slice(s))
create_authority(s, Bytes::copy_from_slice)
}
}

Expand Down Expand Up @@ -481,8 +481,7 @@ impl fmt::Display for Authority {
}

fn host(auth: &str) -> &str {
let host_port = auth
.rsplitn(2, '@')
let host_port = auth.rsplit('@')
.next()
.expect("split always has at least 1 item");

Expand Down Expand Up @@ -615,10 +614,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
Loading

0 comments on commit 9920187

Please sign in to comment.