Skip to content

Commit

Permalink
Resolved clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed Sep 17, 2024
1 parent e3b93fe commit 3b6b364
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 21 deletions.
26 changes: 26 additions & 0 deletions etherparse/src/defrag/ip_defrag_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ where
}
}

impl<Timestamp, CustomChannelId> Default for IpDefragPool<Timestamp, CustomChannelId>
where
Timestamp: Sized + core::fmt::Debug + Clone,
CustomChannelId: Sized + core::fmt::Debug + Clone + core::hash::Hash + Eq + PartialEq,
{
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod test {
use std::cmp::max;
Expand All @@ -269,6 +279,22 @@ mod test {
}
}

#[test]
fn default() {
{
let pool: IpDefragPool<(), ()> = Default::default();
assert_eq!(pool.active.len(), 0);
assert_eq!(pool.finished_data_bufs.len(), 0);
assert_eq!(pool.finished_section_bufs.len(), 0);
}
{
let pool: IpDefragPool<u32, (u32, u32)> = Default::default();
assert_eq!(pool.active.len(), 0);
assert_eq!(pool.finished_data_bufs.len(), 0);
assert_eq!(pool.finished_section_bufs.len(), 0);
}
}

fn build_packet<CustomChannelId: core::hash::Hash + Eq + PartialEq + Clone + Sized>(
id: IpFragId<CustomChannelId>,
offset: u16,
Expand Down
8 changes: 6 additions & 2 deletions etherparse/src/err/from_slice_error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use super::*;

/// Type aggregating errors that can be caused by decoding from a slice. This type can be used
/// as a "catch all" type for errors caused by `from_slice` functions
/// "Catch all" error for all `from_slice` errors (supports automatic conversion from all
/// other slice errors).
///
/// This type aggregates all errors that can be caused by decoding from a slice.
///
/// This type can be used as a "catch all" type for errors caused by `from_slice` functions
/// as all errors from these functions can be converted into this type.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum FromSliceError {
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/lax_packet_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl<'a> LaxPacketHeaders<'a> {
/// }
///
/// ```
pub fn from_ip(slice: &'a [u8]) -> Result<LaxPacketHeaders, err::ip::LaxHeaderSliceError> {
pub fn from_ip(slice: &'a [u8]) -> Result<LaxPacketHeaders<'a>, err::ip::LaxHeaderSliceError> {
let mut result = Self {
link: None,
vlan: None,
Expand Down
6 changes: 3 additions & 3 deletions etherparse/src/lax_sliced_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a> LaxSlicedPacket<'a> {
/// }
///
/// ```
pub fn from_ethernet(slice: &'a [u8]) -> Result<LaxSlicedPacket, err::LenError> {
pub fn from_ethernet(slice: &'a [u8]) -> Result<LaxSlicedPacket<'a>, err::LenError> {
LaxSlicedPacketCursor::parse_from_ethernet2(slice)
}

Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a> LaxSlicedPacket<'a> {
/// println!("transport: {:?}", packet.transport);
///
/// ```
pub fn from_ether_type(ether_type: EtherType, slice: &'a [u8]) -> LaxSlicedPacket {
pub fn from_ether_type(ether_type: EtherType, slice: &'a [u8]) -> LaxSlicedPacket<'a> {
LaxSlicedPacketCursor::parse_from_ether_type(ether_type, slice)
}

Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'a> LaxSlicedPacket<'a> {
/// }
/// }
/// ```
pub fn from_ip(slice: &'a [u8]) -> Result<LaxSlicedPacket, err::ip::LaxHeaderSliceError> {
pub fn from_ip(slice: &'a [u8]) -> Result<LaxSlicedPacket<'a>, err::ip::LaxHeaderSliceError> {
LaxSlicedPacketCursor::parse_from_ip(slice)
}

Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/lax_sliced_packet_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a> LaxSlicedPacketCursor<'a> {
self.slice_transport(payload)
}

fn slice_transport(mut self, slice: LaxIpPayloadSlice<'a>) -> LaxSlicedPacket {
fn slice_transport(mut self, slice: LaxIpPayloadSlice<'a>) -> LaxSlicedPacket<'a> {
use err::packet::SliceError as O;
if slice.fragmented || self.result.stop_err.is_some() {
// if an error occured in an upper layer or the payload is fragmented
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/net/ip_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ impl IpHeaders {
/// parse packets returned via ICMP as these usually only contain the start.
/// * Parsing packets where the `payload_length` (in the IPv6 header) has not
/// yet been set. This can be useful when parsing packets which have been
/// recorded in a layer before the length field was set (e.g. before the operating
/// recorded in a layer before the length field was set (e.g. before the operating
/// system set the length fields).
///
/// # Differences to `from_slice`:
Expand Down
6 changes: 3 additions & 3 deletions etherparse/src/net/ipv4_exts_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> Ipv4ExtensionsSlice<'a> {
pub fn from_slice(
start_ip_number: IpNumber,
start_slice: &'a [u8],
) -> Result<(Ipv4ExtensionsSlice, IpNumber, &[u8]), err::ip_auth::HeaderSliceError> {
) -> Result<(Ipv4ExtensionsSlice<'a>, IpNumber, &'a [u8]), err::ip_auth::HeaderSliceError> {
use ip_number::*;
if AUTH == start_ip_number {
let header = IpAuthHeaderSlice::from_slice(start_slice)?;
Expand Down Expand Up @@ -116,9 +116,9 @@ impl<'a> Ipv4ExtensionsSlice<'a> {
start_ip_number: IpNumber,
start_slice: &'a [u8],
) -> (
Ipv4ExtensionsSlice,
Ipv4ExtensionsSlice<'a>,
IpNumber,
&[u8],
&'a [u8],
Option<err::ip_auth::HeaderSliceError>,
) {
use ip_number::*;
Expand Down
5 changes: 3 additions & 2 deletions etherparse/src/net/ipv6_exts_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl<'a> Ipv6ExtensionsSlice<'a> {
pub fn from_slice(
start_ip_number: IpNumber,
start_slice: &'a [u8],
) -> Result<(Ipv6ExtensionsSlice, IpNumber, &'a [u8]), err::ipv6_exts::HeaderSliceError> {
) -> Result<(Ipv6ExtensionsSlice<'a>, IpNumber, &'a [u8]), err::ipv6_exts::HeaderSliceError>
{
let mut rest = start_slice;
let mut next_header = start_ip_number;
let mut fragmented = false;
Expand Down Expand Up @@ -134,7 +135,7 @@ impl<'a> Ipv6ExtensionsSlice<'a> {
start_ip_number: IpNumber,
start_slice: &'a [u8],
) -> (
Ipv6ExtensionsSlice,
Ipv6ExtensionsSlice<'a>,
IpNumber,
&'a [u8],
Option<(err::ipv6_exts::HeaderSliceError, err::Layer)>,
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/net/ipv6_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'a> Ipv6Slice<'a> {
/// parse packets returned via ICMP as these usually only contain the start.
/// * Parsing packets where the `payload_length` (in the IPv6 header) has not
/// yet been set. This can be useful when parsing packets which have been
/// recorded in a layer before the length field was set (e.g. before the operating
/// recorded in a layer before the length field was set (e.g. before the operating
/// system set the length fields).
///
/// # Differences to `from_slice`:
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/net/lax_ipv6_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> LaxIpv6Slice<'a> {
/// parse packets returned via ICMP as these usually only contain the start.
/// * Parsing packets where the `payload_length` (in the IPv6 header) has not
/// yet been set. This can be useful when parsing packets which have been
/// recorded in a layer before the length field was set (e.g. before the operating
/// recorded in a layer before the length field was set (e.g. before the operating
/// system set the length fields).
///
/// # Differences to `from_slice`:
Expand Down
6 changes: 4 additions & 2 deletions etherparse/src/packet_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl<'a> PacketHeaders<'a> {
/// }
/// }
/// ```
pub fn from_ethernet_slice(slice: &'a [u8]) -> Result<PacketHeaders, err::packet::SliceError> {
pub fn from_ethernet_slice(
slice: &'a [u8],
) -> Result<PacketHeaders<'a>, err::packet::SliceError> {
use err::packet::SliceError::Len;

let (ethernet, rest) = Ethernet2Header::from_slice(slice).map_err(Len)?;
Expand Down Expand Up @@ -139,7 +141,7 @@ impl<'a> PacketHeaders<'a> {
pub fn from_ether_type(
mut ether_type: EtherType,
slice: &'a [u8],
) -> Result<PacketHeaders, err::packet::SliceError> {
) -> Result<PacketHeaders<'a>, err::packet::SliceError> {
use err::packet::SliceError::*;

let mut rest = slice;
Expand Down
8 changes: 4 additions & 4 deletions etherparse/src/sliced_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> SlicedPacket<'a> {
/// }
/// }
/// ```
pub fn from_ethernet(data: &'a [u8]) -> Result<SlicedPacket, err::packet::SliceError> {
pub fn from_ethernet(data: &'a [u8]) -> Result<SlicedPacket<'a>, err::packet::SliceError> {
SlicedPacketCursor::new(data).slice_ethernet2()
}

Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a> SlicedPacket<'a> {
/// }
/// }
/// ```
pub fn from_linux_sll(data: &'a [u8]) -> Result<SlicedPacket, err::packet::SliceError> {
pub fn from_linux_sll(data: &'a [u8]) -> Result<SlicedPacket<'a>, err::packet::SliceError> {
SlicedPacketCursor::new(data).slice_linux_sll()
}

Expand Down Expand Up @@ -191,7 +191,7 @@ impl<'a> SlicedPacket<'a> {
pub fn from_ether_type(
ether_type: EtherType,
data: &'a [u8],
) -> Result<SlicedPacket, err::packet::SliceError> {
) -> Result<SlicedPacket<'a>, err::packet::SliceError> {
use ether_type::*;
let mut cursor = SlicedPacketCursor::new(data);
cursor.result.link = Some(LinkSlice::EtherPayload(EtherPayloadSlice {
Expand Down Expand Up @@ -242,7 +242,7 @@ impl<'a> SlicedPacket<'a> {
/// }
/// }
/// ```
pub fn from_ip(data: &'a [u8]) -> Result<SlicedPacket, err::packet::SliceError> {
pub fn from_ip(data: &'a [u8]) -> Result<SlicedPacket<'a>, err::packet::SliceError> {
SlicedPacketCursor::new(data).slice_ip()
}

Expand Down

0 comments on commit 3b6b364

Please sign in to comment.