Improve code styling

This commit is contained in:
Tobias Ottenweller 2022-04-03 17:10:59 +02:00
parent bc278b7d39
commit c67c940ba9

View File

@ -38,12 +38,6 @@ pub enum DNSRCode {
NOTINZONE = 10, NOTINZONE = 10,
} }
#[derive(Debug)]
pub enum DNSParseErr {
DatagramLengthError,
SliceError(std::array::TryFromSliceError)
}
impl From<u16> for DNSRCode { impl From<u16> for DNSRCode {
fn from(val: u16) -> Self { fn from(val: u16) -> Self {
match val { match val {
@ -115,9 +109,9 @@ impl DNSHeader {
const OPCODE_OFFSET: u16 = 1; const OPCODE_OFFSET: u16 = 1;
const RCODE_OFFSET: u16 = 11; const RCODE_OFFSET: u16 = 11;
pub fn from_udp_datagram(datagram: &[u8]) -> Result<Self, DNSParseErr> { pub fn from_udp_datagram(datagram: &[u8]) -> Result<Self, DNSParseError> {
if datagram.len() < 11 { if datagram.len() < 11 {
return Err(DNSParseErr::DatagramLengthError); return Err(DNSParseError::DatagramLengthError);
} }
let id = u16::from_be_bytes((&datagram[..2]).try_into()?); let id = u16::from_be_bytes((&datagram[..2]).try_into()?);
@ -157,8 +151,14 @@ impl DNSHeader {
} }
} }
impl From<std::array::TryFromSliceError> for DNSParseErr { #[derive(Debug)]
pub enum DNSParseError {
DatagramLengthError,
SliceError(std::array::TryFromSliceError)
}
impl From<std::array::TryFromSliceError> for DNSParseError {
fn from(err: std::array::TryFromSliceError) -> Self { fn from(err: std::array::TryFromSliceError) -> Self {
DNSParseErr::SliceError(err) DNSParseError::SliceError(err)
} }
} }