diff --git a/src/iface/ethernet.rs b/src/iface/ethernet.rs index 3d64263..7a5d73d 100644 --- a/src/iface/ethernet.rs +++ b/src/iface/ethernet.rs @@ -1519,7 +1519,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> { } } - fn has_neighbor<'a>(&self, addr: &'a IpAddress, timestamp: Instant) -> bool { + fn has_neighbor(&self, addr: &IpAddress, timestamp: Instant) -> bool { match self.route(addr, timestamp) { Ok(routed_addr) => { self.neighbor_cache diff --git a/src/parsers.rs b/src/parsers.rs index 36bad29..bf87cdc 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -88,11 +88,11 @@ impl<'a> Parser<'a> { fn accept_digit(&mut self, hex: bool) -> Result { let digit = self.advance()?; - if digit >= b'0' && digit <= b'9' { + if (b'0'..=b'9').contains(&digit) { Ok(digit - b'0') - } else if hex && digit >= b'a' && digit <= b'f' { + } else if hex && (b'a'..=b'f').contains(&digit) { Ok(digit - b'a' + 10) - } else if hex && digit >= b'A' && digit <= b'F' { + } else if hex && (b'A'..=b'F').contains(&digit) { Ok(digit - b'A' + 10) } else { Err(()) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 8ed45b9..c88f4ef 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -1416,7 +1416,7 @@ impl<'a> TcpSocket<'a> { payload_len, payload_offset); self.rx_buffer.write_unallocated(payload_offset, repr.payload); } - Err(()) => { + Err(_) => { net_debug!("{}:{}:{}: assembler: too many holes to add {} octets at offset {}", self.meta.handle, self.local_endpoint, self.remote_endpoint, payload_len, payload_offset); diff --git a/src/storage/assembler.rs b/src/storage/assembler.rs index 714cf3d..159d93d 100644 --- a/src/storage/assembler.rs +++ b/src/storage/assembler.rs @@ -1,5 +1,8 @@ use core::fmt; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct TooManyHolesError; + /// A contiguous chunk of absent data, followed by a contiguous chunk of present data. #[derive(Debug, Clone, Copy, PartialEq, Eq)] struct Contig { @@ -148,10 +151,10 @@ impl Assembler { } /// Add a contig at the given index, and return a pointer to it. - fn add_contig_at(&mut self, at: usize) -> Result<&mut Contig, ()> { + fn add_contig_at(&mut self, at: usize) -> Result<&mut Contig, TooManyHolesError> { debug_assert!(!self.contigs[at].is_empty()); - if !self.back().is_empty() { return Err(()) } + if !self.back().is_empty() { return Err(TooManyHolesError) } for i in (at + 1..self.contigs.len()).rev() { self.contigs[i] = self.contigs[i - 1]; @@ -163,7 +166,7 @@ impl Assembler { /// Add a new contiguous range to the assembler, and return `Ok(())`, /// or return `Err(())` if too many discontiguities are already recorded. - pub fn add(&mut self, mut offset: usize, mut size: usize) -> Result<(), ()> { + pub fn add(&mut self, mut offset: usize, mut size: usize) -> Result<(), TooManyHolesError> { let mut index = 0; while index != self.contigs.len() && size != 0 { let contig = self.contigs[index]; @@ -413,7 +416,7 @@ mod test { } // Maximum of allowed holes is reached let assr_before = assr.clone(); - assert_eq!(assr.add(1, 3), Err(())); + assert_eq!(assr.add(1, 3), Err(TooManyHolesError)); assert_eq!(assr_before, assr); } diff --git a/src/storage/ring_buffer.rs b/src/storage/ring_buffer.rs index 873140e..6ea46ac 100644 --- a/src/storage/ring_buffer.rs +++ b/src/storage/ring_buffer.rs @@ -129,7 +129,7 @@ impl<'a, T: 'a> RingBuffer<'a, T> { /// or return `Err(Error::Exhausted)` if the buffer is full. /// /// This function is a shortcut for `ring_buf.enqueue_one_with(Ok)`. - pub fn enqueue_one<'b>(&'b mut self) -> Result<&'b mut T> { + pub fn enqueue_one(&mut self) -> Result<&mut T> { self.enqueue_one_with(Ok) } diff --git a/src/wire/ipv6option.rs b/src/wire/ipv6option.rs index d96969c..18e5dce 100644 --- a/src/wire/ipv6option.rs +++ b/src/wire/ipv6option.rs @@ -307,14 +307,6 @@ impl<'a> Ipv6OptionsIterator<'a> { length, data } } - - /// Helper function to return an error in the implementation - /// of `Iterator`. - #[inline] - fn return_err(&mut self, err: Error) -> Option>> { - self.hit_error = true; - Some(Err(err)) - } } impl<'a> Iterator for Ipv6OptionsIterator<'a> { @@ -332,12 +324,14 @@ impl<'a> Iterator for Ipv6OptionsIterator<'a> { Some(Ok(repr)) } Err(e) => { - self.return_err(e) + self.hit_error = true; + Some(Err(e)) } } } Err(e) => { - self.return_err(e) + self.hit_error = true; + Some(Err(e)) } } } else {