mdns_proto/wire/record/
aaaa.rs1use core::net::Ipv6Addr;
4
5use crate::error::{BufferTooShortDetail, ParseError};
6
7#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
9#[allow(clippy::upper_case_acronyms)]
11pub struct AAAA {
12 addr: Ipv6Addr,
13}
14
15impl AAAA {
16 pub fn try_from_rdata(rdata: &[u8]) -> Result<Self, ParseError> {
21 if rdata.len() != 16 {
22 return Err(ParseError::BufferTooShort(BufferTooShortDetail::new(
23 16,
24 0,
25 rdata.len(),
26 )));
27 }
28 let arr: &[u8; 16] = rdata
29 .first_chunk::<16>()
30 .ok_or_else(|| ParseError::BufferTooShort(BufferTooShortDetail::new(16, 0, rdata.len())))?;
31 Ok(Self {
32 addr: Ipv6Addr::from(*arr),
33 })
34 }
35
36 #[inline(always)]
38 pub const fn addr(&self) -> Ipv6Addr {
39 self.addr
40 }
41}
42
43#[cfg(test)]
44#[allow(clippy::unwrap_used)]
45mod tests;