use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; pub trait DataType { const TYPE: u32; const LEN: u32; fn data(&self) -> Vec; } impl DataType for Ipv4Addr { const TYPE: u32 = 7; const LEN: u32 = 4; fn data(&self) -> Vec { self.octets().to_vec() } } impl DataType for Ipv6Addr { const TYPE: u32 = 8; const LEN: u32 = 16; fn data(&self) -> Vec { self.octets().to_vec() } } impl DataType for [u8; N] { const TYPE: u32 = 5; const LEN: u32 = N as u32; fn data(&self) -> Vec { self.to_vec() } } pub fn ip_to_vec(ip: IpAddr) -> Vec { match ip { IpAddr::V4(x) => x.octets().to_vec(), IpAddr::V6(x) => x.octets().to_vec(), } }