#struct #display #show #derive #pnet-packet

macro pnet_show

Derive a show function for pnet_packet's to display the struct similar to scapy

2 releases

Uses new Rust 2024

0.1.1 Aug 11, 2025
0.1.0 Aug 11, 2025

#51 in Network programming

Apache-2.0

5KB

pnet_show

pnet_show is a proc-macro crate, that derives a .show() function for pnet_packet's to display the struct similar to scapy.

First define your struct and add the derive Show.

#[packet]
#[derive(Show)]
pub struct Tether {
    version: u8,
    unknown0: u8,
    tether_type: u8,
    unknown1: u8,
    length: u16be,
    unknown2: u16be,
    unknown3: u32be,
    crc32: u32be,
    options: u16be,
    function_id: u16be,
    #[payload]
    payload: Vec<u8>,
}

Calling now .show() will then return a string displaying the struct including the values as follow:

##[ Tether ]##
 version: 1
 unknown0: 0
 tether_type: 5
 unknown1: 0
 length: 8
 unknown2: 0
 unknown3: 12
 cr032: 1035144919
 options: 257
 function_id: 1601

Dependencies

~89–425KB
~10K SLoC