domain_core/rdata/
rfc3596.rs1use std::{fmt, ops};
8use std::net::Ipv6Addr;
9use std::str::FromStr;
10use bytes::BufMut;
11use ::bits::compose::{Compose, Compress, Compressor};
12use ::bits::parse::{Parse, ParseAll, Parser, ShortBuf};
13use ::bits::rdata::RtypeRecordData;
14use ::iana::Rtype;
15use ::master::scan::{CharSource, Scan, Scanner, ScanError};
16
17
18#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
21pub struct Aaaa {
22    addr: Ipv6Addr
23}
24
25impl Aaaa {
26    pub fn new(addr: Ipv6Addr) -> Aaaa {
27        Aaaa { addr }
28    }
29
30    pub fn addr(&self) -> Ipv6Addr { self.addr }
31    pub fn set_addr(&mut self, addr: Ipv6Addr) { self.addr = addr }
32}
33
34
35impl From<Ipv6Addr> for Aaaa {
38    fn from(addr: Ipv6Addr) -> Self {
39        Self::new(addr)
40    }
41}
42
43impl From<Aaaa> for Ipv6Addr {
44    fn from(data: Aaaa) -> Self {
45        data.addr
46    }
47}
48
49impl FromStr for Aaaa {
50    type Err = <Ipv6Addr as FromStr>::Err;
51
52    fn from_str(s: &str) -> Result<Self, Self::Err> {
53        Ipv6Addr::from_str(s).map(Aaaa::new)
54    }
55}
56
57
58impl Parse for Aaaa {
61    type Err = <Ipv6Addr as Parse>::Err;
62
63    fn parse(parser: &mut Parser) -> Result<Self, Self::Err> {
64        Ipv6Addr::parse(parser).map(Self::new)
65    }
66
67    fn skip(parser: &mut Parser) -> Result<(), Self::Err> {
68        Ipv6Addr::skip(parser)
69    }
70}
71
72impl ParseAll for Aaaa {
73    type Err = <Ipv6Addr as ParseAll>::Err;
74
75    fn parse_all(parser: &mut Parser, len: usize) -> Result<Self, Self::Err> {
76        Ipv6Addr::parse_all(parser, len).map(Self::new)
77    }
78}
79
80impl Compose for Aaaa {
81    fn compose_len(&self) -> usize {
82        16
83    }
84
85    fn compose<B: BufMut>(&self, buf: &mut B) {
86        self.addr.compose(buf)
87    }
88}
89
90impl Compress for Aaaa {
91    fn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf> {
92        buf.compose(self)
93    }
94}
95
96
97impl Scan for Aaaa {
100    fn scan<C: CharSource>(scanner: &mut Scanner<C>)
101                           -> Result<Self, ScanError> {
102        scanner.scan_string_phrase(|res| {
103            Aaaa::from_str(&res).map_err(Into::into)
104        })
105    }
106}
107
108impl fmt::Display for Aaaa {
109    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110        self.addr.fmt(f)
111    }
112}
113
114
115impl RtypeRecordData for Aaaa {
118    const RTYPE: Rtype = Rtype::Aaaa;
119}
120
121
122impl ops::Deref for Aaaa {
125    type Target = Ipv6Addr;
126
127    fn deref(&self) -> &Self::Target {
128        &self.addr
129    }
130}
131
132impl ops::DerefMut for Aaaa {
133    fn deref_mut(&mut self) -> &mut Self::Target {
134        &mut self.addr
135    }
136}
137
138
139impl AsRef<Ipv6Addr> for Aaaa {
142    fn as_ref(&self) -> &Ipv6Addr {
143        &self.addr
144    }
145}
146
147impl AsMut<Ipv6Addr> for Aaaa {
148    fn as_mut(&mut self) -> &mut Ipv6Addr {
149        &mut self.addr
150    }
151}
152
153
154pub mod parsed {
157    pub use super::Aaaa;
158}