hickory_proto/rr/dnssec/rdata/
cds.rsuse std::{fmt, ops::Deref};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::{
error::ProtoResult,
rr::{RData, RecordData, RecordDataDecodable, RecordType},
serialize::binary::{BinDecoder, BinEncodable, BinEncoder, Restrict},
};
use super::{DNSSECRData, DS};
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct CDS(DS);
impl Deref for CDS {
type Target = DS;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl BinEncodable for CDS {
fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
self.0.emit(encoder)
}
}
impl<'r> RecordDataDecodable<'r> for CDS {
fn read_data(decoder: &mut BinDecoder<'r>, length: Restrict<u16>) -> ProtoResult<Self> {
DS::read_data(decoder, length).map(Self)
}
}
impl RecordData for CDS {
fn try_from_rdata(data: RData) -> Result<Self, RData> {
match data {
RData::DNSSEC(DNSSECRData::CDS(cds)) => Ok(cds),
_ => Err(data),
}
}
fn try_borrow(data: &RData) -> Option<&Self> {
match data {
RData::DNSSEC(DNSSECRData::CDS(cds)) => Some(cds),
_ => None,
}
}
fn record_type(&self) -> RecordType {
RecordType::CDS
}
fn into_rdata(self) -> RData {
RData::DNSSEC(DNSSECRData::CDS(self))
}
}
impl fmt::Display for CDS {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{}", self.0)
}
}