From 7b943c4bd7bbcd9e6f76bc240a3ca815d90b73d2 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 2 Mar 2026 11:21:56 +1100 Subject: [PATCH 1/2] feat: implement more traits for header types --- etherparse/src/net/ipv4_header.rs | 2 +- etherparse/src/net/ipv4_options.rs | 2 +- etherparse/src/net/ipv6_header.rs | 2 +- etherparse/src/transport/tcp_header.rs | 2 +- etherparse/src/transport/tcp_options.rs | 2 +- etherparse/src/transport/udp_header.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etherparse/src/net/ipv4_header.rs b/etherparse/src/net/ipv4_header.rs index 3a332b77..cfd50e35 100644 --- a/etherparse/src/net/ipv4_header.rs +++ b/etherparse/src/net/ipv4_header.rs @@ -32,7 +32,7 @@ use arrayvec::ArrayVec; /// assert_eq!(header, decoded); /// assert_eq!(slice_rest, &[]); /// ``` -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct Ipv4Header { /// Differentiated Services Code Point pub dscp: IpDscp, diff --git a/etherparse/src/net/ipv4_options.rs b/etherparse/src/net/ipv4_options.rs index f741a072..72cab066 100644 --- a/etherparse/src/net/ipv4_options.rs +++ b/etherparse/src/net/ipv4_options.rs @@ -34,7 +34,7 @@ use core::borrow::{Borrow, BorrowMut}; /// assert_eq!(result, Err(BadOptionsLen { bad_len: 3 })); /// } /// ``` -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct Ipv4Options { pub(crate) len: u8, pub(crate) buf: [u8; 40], diff --git a/etherparse/src/net/ipv6_header.rs b/etherparse/src/net/ipv6_header.rs index 454d99aa..747759d3 100644 --- a/etherparse/src/net/ipv6_header.rs +++ b/etherparse/src/net/ipv6_header.rs @@ -1,7 +1,7 @@ use crate::{err::ValueTooBigError, *}; /// IPv6 header according to rfc8200. -#[derive(Clone, Debug, Eq, PartialEq, Default)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] pub struct Ipv6Header { pub traffic_class: u8, /// If non 0 serves as a hint to router and switches with multiple outbound paths that these packets should stay on the same path, so that they will not be reordered. diff --git a/etherparse/src/transport/tcp_header.rs b/etherparse/src/transport/tcp_header.rs index a26ce532..a8c41b2a 100644 --- a/etherparse/src/transport/tcp_header.rs +++ b/etherparse/src/transport/tcp_header.rs @@ -19,7 +19,7 @@ pub const TCP_MAXIMUM_DATA_OFFSET: u8 = 0xf; /// TCP header according to rfc 793. /// /// Field descriptions copied from RFC 793 page 15++ -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct TcpHeader { /// The source port number. pub source_port: u16, diff --git a/etherparse/src/transport/tcp_options.rs b/etherparse/src/transport/tcp_options.rs index 8c2720b0..33efe558 100644 --- a/etherparse/src/transport/tcp_options.rs +++ b/etherparse/src/transport/tcp_options.rs @@ -125,7 +125,7 @@ use crate::{tcp_option, TcpHeader, TcpOptionElement, TcpOptionWriteError, TcpOpt /// ] /// ); /// ``` -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct TcpOptions { /// Number of bytes in the buffer. pub(crate) len: u8, diff --git a/etherparse/src/transport/udp_header.rs b/etherparse/src/transport/udp_header.rs index d4a5279a..94b68ea0 100644 --- a/etherparse/src/transport/udp_header.rs +++ b/etherparse/src/transport/udp_header.rs @@ -1,7 +1,7 @@ use crate::{err::ValueTooBigError, *}; /// Udp header according to rfc768. -#[derive(Clone, Debug, Eq, PartialEq, Default)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] pub struct UdpHeader { /// Source port of the packet (optional). pub source_port: u16, From efb66e37b4a8abcb856ed665c8395eec51ba456b Mon Sep 17 00:00:00 2001 From: Julian Schmid Date: Fri, 6 Mar 2026 18:45:11 +0100 Subject: [PATCH 2/2] Removed copy trait --- etherparse/src/net/ipv4_header.rs | 2 +- etherparse/src/net/ipv4_options.rs | 2 +- etherparse/src/net/ipv6_header.rs | 2 +- etherparse/src/transport/tcp_header.rs | 2 +- etherparse/src/transport/tcp_options.rs | 2 +- etherparse/src/transport/udp_header.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etherparse/src/net/ipv4_header.rs b/etherparse/src/net/ipv4_header.rs index cfd50e35..cf6733fd 100644 --- a/etherparse/src/net/ipv4_header.rs +++ b/etherparse/src/net/ipv4_header.rs @@ -32,7 +32,7 @@ use arrayvec::ArrayVec; /// assert_eq!(header, decoded); /// assert_eq!(slice_rest, &[]); /// ``` -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct Ipv4Header { /// Differentiated Services Code Point pub dscp: IpDscp, diff --git a/etherparse/src/net/ipv4_options.rs b/etherparse/src/net/ipv4_options.rs index 72cab066..f741a072 100644 --- a/etherparse/src/net/ipv4_options.rs +++ b/etherparse/src/net/ipv4_options.rs @@ -34,7 +34,7 @@ use core::borrow::{Borrow, BorrowMut}; /// assert_eq!(result, Err(BadOptionsLen { bad_len: 3 })); /// } /// ``` -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Ipv4Options { pub(crate) len: u8, pub(crate) buf: [u8; 40], diff --git a/etherparse/src/net/ipv6_header.rs b/etherparse/src/net/ipv6_header.rs index 747759d3..afec78b9 100644 --- a/etherparse/src/net/ipv6_header.rs +++ b/etherparse/src/net/ipv6_header.rs @@ -1,7 +1,7 @@ use crate::{err::ValueTooBigError, *}; /// IPv6 header according to rfc8200. -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] pub struct Ipv6Header { pub traffic_class: u8, /// If non 0 serves as a hint to router and switches with multiple outbound paths that these packets should stay on the same path, so that they will not be reordered. diff --git a/etherparse/src/transport/tcp_header.rs b/etherparse/src/transport/tcp_header.rs index a8c41b2a..d442bef6 100644 --- a/etherparse/src/transport/tcp_header.rs +++ b/etherparse/src/transport/tcp_header.rs @@ -19,7 +19,7 @@ pub const TCP_MAXIMUM_DATA_OFFSET: u8 = 0xf; /// TCP header according to rfc 793. /// /// Field descriptions copied from RFC 793 page 15++ -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct TcpHeader { /// The source port number. pub source_port: u16, diff --git a/etherparse/src/transport/tcp_options.rs b/etherparse/src/transport/tcp_options.rs index 33efe558..8c2720b0 100644 --- a/etherparse/src/transport/tcp_options.rs +++ b/etherparse/src/transport/tcp_options.rs @@ -125,7 +125,7 @@ use crate::{tcp_option, TcpHeader, TcpOptionElement, TcpOptionWriteError, TcpOpt /// ] /// ); /// ``` -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct TcpOptions { /// Number of bytes in the buffer. pub(crate) len: u8, diff --git a/etherparse/src/transport/udp_header.rs b/etherparse/src/transport/udp_header.rs index 94b68ea0..6c2372aa 100644 --- a/etherparse/src/transport/udp_header.rs +++ b/etherparse/src/transport/udp_header.rs @@ -1,7 +1,7 @@ use crate::{err::ValueTooBigError, *}; /// Udp header according to rfc768. -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Default, PartialOrd, Ord)] pub struct UdpHeader { /// Source port of the packet (optional). pub source_port: u16,