use crate::{error::ParseError, wire::NameRef};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Cname<'a> {
target: NameRef<'a>,
}
impl<'a> Cname<'a> {
pub fn try_from_message(
message: &'a [u8],
rdata_offset: usize,
rdata_len: usize,
) -> Result<Self, ParseError> {
let (target, consumed) = NameRef::try_parse(message, rdata_offset)?;
if consumed != rdata_len {
return Err(ParseError::BufferTooShort(
crate::error::BufferTooShortDetail::new(consumed, rdata_offset, rdata_len),
));
}
Ok(Self { target })
}
#[inline(always)]
pub const fn target(&self) -> &NameRef<'a> {
&self.target
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests;