From 2cb8acd31d9fa3bd32f7b2906f13f0edfe7a1284 Mon Sep 17 00:00:00 2001 From: landhb Date: Wed, 1 Feb 2023 10:59:02 -0500 Subject: [PATCH 1/2] Add blanket impls of Packet for Box and &T. --- pnet_macros_support/src/packet.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pnet_macros_support/src/packet.rs b/pnet_macros_support/src/packet.rs index d29021f5..aa2a41e5 100644 --- a/pnet_macros_support/src/packet.rs +++ b/pnet_macros_support/src/packet.rs @@ -23,6 +23,31 @@ pub trait Packet { fn payload(&self) -> &[u8]; } +/// Blanket impl for Boxed objects +impl Packet for alloc::boxed::Box { + /// Retrieve the underlying buffer for the packet. + fn packet(&self) -> &[u8] { + self.packet() + } + + /// Retrieve the payload for the packet. + fn payload(&self) -> &[u8] { + self.packet() + } +} + +impl Packet for &T { + /// Retrieve the underlying buffer for the packet. + fn packet(&self) -> &[u8] { + self.packet() + } + + /// Retrieve the payload for the packet. + fn payload(&self) -> &[u8] { + self.packet() + } +} + /// Represents a generic, mutable, network packet. pub trait MutablePacket: Packet { /// Retreive the underlying, mutable, buffer for the packet. From 54c3f13c190e6daa3cccd3081555fb8bbb983084 Mon Sep 17 00:00:00 2001 From: landhb Date: Wed, 1 Feb 2023 13:53:28 -0500 Subject: [PATCH 2/2] Fix typo on payload method. --- pnet_macros_support/src/packet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnet_macros_support/src/packet.rs b/pnet_macros_support/src/packet.rs index aa2a41e5..7abd3248 100644 --- a/pnet_macros_support/src/packet.rs +++ b/pnet_macros_support/src/packet.rs @@ -32,7 +32,7 @@ impl Packet for alloc::boxed::Box { /// Retrieve the payload for the packet. fn payload(&self) -> &[u8] { - self.packet() + self.payload() } } @@ -44,7 +44,7 @@ impl Packet for &T { /// Retrieve the payload for the packet. fn payload(&self) -> &[u8] { - self.packet() + self.payload() } }