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/// [`RegistrationHandle::get_default_txt_record`][crate::RegistrationHandle::method.get_default_txt_record])
12///
13/// Also keeps the underlying [`Registration`][crate::Registration] or
14/// [`Connection`][crate::Connection] alive.
15pub struct Record(inner::DNSRecord);
16
17impl Record {
18	/// Type of the record
19	pub fn rr_type(&self) -> Type {
20		self.0.rr_type()
21	}
22
23	/// Update record
24	///
25	/// Cannot change type or class of record.
26	///
27	/// See [`DNSServiceUpdateRecord`](https://developer.apple.com/documentation/dnssd/1804739-dnsserviceupdaterecord).
28	#[doc(alias = "DNSServiceUpdateRecord")]
29	pub fn update_record(&self, rdata: &[u8], ttl: u32) -> io::Result<()> {
30		self.0.update_record(0 /* no flags */, rdata, ttl)?;
31		Ok(())
32	}
33
34	/// Keep record alive for as long as the underlying
35	/// [`Registration`][crate::Registration] or
36	/// [`Connection`][crate::Connection] lives
37	pub fn keep(self) {
38		self.0.keep()
39	}
40}
41
42impl From<inner::DNSRecord> for Record {
43	fn from(r: inner::DNSRecord) -> Self {
44		Self(r)
45	}
46}