use bytes::{Bytes, Buf}; use errors::*; use std::io::Cursor; mod std_impls; pub trait DnsPacketData: Sized { fn deserialize(data: &mut Cursor) -> Result; } pub fn deserialize(data: Bytes) -> Result where T: DnsPacketData { let mut c = Cursor::new(data); let result = T::deserialize(&mut c)?; if c.remaining() != 0 { bail!("data remaining: {}", c.remaining()) } Ok(result) }