Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blanket impls of Packet for Box<T> and &T. #599

Merged
merged 2 commits into from Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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