Improve code styling
This commit is contained in:
parent
bc278b7d39
commit
c67c940ba9
20
src/proto.rs
20
src/proto.rs
@ -38,12 +38,6 @@ pub enum DNSRCode {
|
||||
NOTINZONE = 10,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DNSParseErr {
|
||||
DatagramLengthError,
|
||||
SliceError(std::array::TryFromSliceError)
|
||||
}
|
||||
|
||||
impl From<u16> for DNSRCode {
|
||||
fn from(val: u16) -> Self {
|
||||
match val {
|
||||
@ -115,9 +109,9 @@ impl DNSHeader {
|
||||
const OPCODE_OFFSET: u16 = 1;
|
||||
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 {
|
||||
return Err(DNSParseErr::DatagramLengthError);
|
||||
return Err(DNSParseError::DatagramLengthError);
|
||||
}
|
||||
|
||||
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 {
|
||||
DNSParseErr::SliceError(err)
|
||||
DNSParseError::SliceError(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user