#[non_exhaustive]pub enum Packet<'a> {
Ethernet(EthernetPacket<'a>),
Arp(ArpPacket<'a>),
Ipv4(Ipv4Packet<'a>),
Ipv6(Ipv6Packet<'a>),
Tcp(TcpPacket<'a>),
Udp(UdpPacket<'a>),
Icmp(IcmpPacket<'a>),
Icmpv6(Icmpv6Packet<'a>),
}Expand description
Unified packet enum covering all supported L2–L4 protocols.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Ethernet(EthernetPacket<'a>)
Arp(ArpPacket<'a>)
Ipv4(Ipv4Packet<'a>)
Ipv6(Ipv6Packet<'a>)
Tcp(TcpPacket<'a>)
Udp(UdpPacket<'a>)
Icmp(IcmpPacket<'a>)
Icmpv6(Icmpv6Packet<'a>)
Implementations§
Source§impl<'a> Packet<'a>
impl<'a> Packet<'a>
Sourcepub fn accept<V: PacketVisitor>(&self, visitor: &mut V) -> V::Output
pub fn accept<V: PacketVisitor>(&self, visitor: &mut V) -> V::Output
Accept a visitor — the double-dispatch entry point.
This is the Visitor pattern’s core mechanism: the Packet dispatches
to the correct visit_* method based on its variant at runtime.
Sourcepub fn inner(&self) -> Option<Packet<'a>>
pub fn inner(&self) -> Option<Packet<'a>>
Return the encapsulated inner protocol, if any.
This is the Composite pattern: each protocol layer can contain another, forming a recursive tree. Walk the full stack with:
ⓘ
let mut current = Some(packet);
while let Some(p) = current {
println!("{}", p.protocol_name());
current = p.inner();
}Sourcepub fn protocol_name(&self) -> &'static str
pub fn protocol_name(&self) -> &'static str
Human-readable protocol name for this packet layer.
Trait Implementations§
Source§impl<'a> From<EthernetPacket<'a>> for Packet<'a>
impl<'a> From<EthernetPacket<'a>> for Packet<'a>
Source§fn from(p: EthernetPacket<'a>) -> Self
fn from(p: EthernetPacket<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<IcmpPacket<'a>> for Packet<'a>
impl<'a> From<IcmpPacket<'a>> for Packet<'a>
Source§fn from(p: IcmpPacket<'a>) -> Self
fn from(p: IcmpPacket<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<Icmpv6Packet<'a>> for Packet<'a>
impl<'a> From<Icmpv6Packet<'a>> for Packet<'a>
Source§fn from(p: Icmpv6Packet<'a>) -> Self
fn from(p: Icmpv6Packet<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<Ipv4Packet<'a>> for Packet<'a>
impl<'a> From<Ipv4Packet<'a>> for Packet<'a>
Source§fn from(p: Ipv4Packet<'a>) -> Self
fn from(p: Ipv4Packet<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<Ipv6Packet<'a>> for Packet<'a>
impl<'a> From<Ipv6Packet<'a>> for Packet<'a>
Source§fn from(p: Ipv6Packet<'a>) -> Self
fn from(p: Ipv6Packet<'a>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a> Freeze for Packet<'a>
impl<'a> RefUnwindSafe for Packet<'a>
impl<'a> Send for Packet<'a>
impl<'a> Sync for Packet<'a>
impl<'a> Unpin for Packet<'a>
impl<'a> UnsafeUnpin for Packet<'a>
impl<'a> UnwindSafe for Packet<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more