use core::net::Ipv6Addr;
use crate::error::{BufferTooShortDetail, ParseError};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[allow(clippy::upper_case_acronyms)]
pub struct AAAA {
addr: Ipv6Addr,
}
impl AAAA {
pub fn try_from_rdata(rdata: &[u8]) -> Result<Self, ParseError> {
if rdata.len() != 16 {
return Err(ParseError::BufferTooShort(BufferTooShortDetail::new(
16,
0,
rdata.len(),
)));
}
let arr: &[u8; 16] = rdata
.first_chunk::<16>()
.ok_or_else(|| ParseError::BufferTooShort(BufferTooShortDetail::new(16, 0, rdata.len())))?;
Ok(Self {
addr: Ipv6Addr::from(*arr),
})
}
#[inline(always)]
pub const fn addr(&self) -> Ipv6Addr {
self.addr
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests;