hickory_proto/rr/rdata/
https.rs1use core::{fmt, ops::Deref};
11
12#[cfg(feature = "serde")]
13use serde::{Deserialize, Serialize};
14
15use crate::{
16 error::ProtoResult,
17 rr::{RData, RecordData, RecordDataDecodable, RecordType},
18 serialize::binary::{BinDecoder, BinEncodable, BinEncoder, DecodeError, Restrict},
19};
20
21use super::SVCB;
22
23#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
25#[derive(Debug, PartialEq, Eq, Hash, Clone)]
26pub struct HTTPS(pub SVCB);
27
28impl Deref for HTTPS {
29 type Target = SVCB;
30
31 fn deref(&self) -> &Self::Target {
32 &self.0
33 }
34}
35
36impl BinEncodable for HTTPS {
37 fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()> {
38 self.0.emit(encoder)
39 }
40}
41
42impl<'r> RecordDataDecodable<'r> for HTTPS {
43 fn read_data(decoder: &mut BinDecoder<'r>, length: Restrict<u16>) -> Result<Self, DecodeError> {
44 SVCB::read_data(decoder, length).map(Self)
45 }
46}
47
48impl RecordData for HTTPS {
49 fn try_borrow(data: &RData) -> Option<&Self> {
50 match data {
51 RData::HTTPS(https) => Some(https),
52 _ => None,
53 }
54 }
55
56 fn record_type(&self) -> RecordType {
57 RecordType::HTTPS
58 }
59
60 fn into_rdata(self) -> RData {
61 RData::HTTPS(self)
62 }
63}
64
65impl fmt::Display for HTTPS {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
67 write!(f, "{}", self.0)
68 }
69}