async_dnssd/service/records.rs
1use std::io;
2
3use crate::{
4 dns_consts::Type,
5 inner,
6};
7
8/// A successful record registration
9///
10/// Releases the record when dropped (unless it is a
11/// [`Registration::get_default_txt_record`] or a
12/// [`Register::get_default_txt_record`])
13///
14/// Also keeps the underlying [`Registration`] or [`Connection`] alive.
15///
16/// [`Registration::get_default_txt_record`]: struct.Registration.html#method.get_default_txt_record
17/// [`Register::get_default_txt_record`]: struct.Register.html#method.get_default_txt_record
18/// [`Registration`]: struct.Registration.html
19/// [`Connection`]: struct.Connection.html
20pub struct Record(inner::DNSRecord);
21
22impl Record {
23 /// Type of the record
24 pub fn rr_type(&self) -> Type {
25 self.0.rr_type()
26 }
27
28 /// Update record
29 ///
30 /// Cannot change type or class of record.
31 ///
32 /// See [`DNSServiceUpdateRecord`](https://developer.apple.com/documentation/dnssd/1804739-dnsserviceupdaterecord).
33 #[doc(alias = "DNSServiceUpdateRecord")]
34 pub fn update_record(&self, rdata: &[u8], ttl: u32) -> io::Result<()> {
35 self.0.update_record(0 /* no flags */, rdata, ttl)?;
36 Ok(())
37 }
38
39 /// Keep record alive for as long as the underlying
40 /// [`Registration`](struct.Registration.html) or
41 /// [`Connection`](struct.Connection.html) lives
42 pub fn keep(self) {
43 self.0.keep()
44 }
45}
46
47impl From<inner::DNSRecord> for Record {
48 fn from(r: inner::DNSRecord) -> Self {
49 Self(r)
50 }
51}