Skip to content

Commit

Permalink
Merge pull request #599 from landhb/blanket_impls
Browse files Browse the repository at this point in the history
Add blanket impls of Packet for Box<T> and &T.
  • Loading branch information
mrmonday committed Feb 3, 2023
2 parents c9d7c1c + 54c3f13 commit 9a3a0ba
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pnet_macros_support/src/packet.rs
Expand Up @@ -23,6 +23,31 @@ pub trait Packet {
fn payload(&self) -> &[u8];
}

/// Blanket impl for Boxed objects
impl<T: Packet> Packet for alloc::boxed::Box<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.payload()
}
}

impl<T: Packet> 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.payload()
}
}

/// Represents a generic, mutable, network packet.
pub trait MutablePacket: Packet {
/// Retreive the underlying, mutable, buffer for the packet.
Expand Down

0 comments on commit 9a3a0ba

Please sign in to comment.