Struct async_dnssd::TxtRecord
source · pub struct TxtRecord(_);
Expand description
Key-Value container that uses DNS TXT
RDATA as representation
The binary representation can be used as RDATA for DNS-SD TXT Records
(see RFC 6763, section 6).
Each entry results in one string in the TXT
represenation; TXT
RDATA contains many (but at least one) possibly empty strings, each
up to 255 bytes.
Key and value are separated by the first =
in an entry, and the
key must consist of printable ASCII characters (0x20…0x7E) apart
from =
. Keys should be 9 characters or fewer.
Values can be any binary string (but the total length of an entry cannot exceed 255 bytes).
An entry also can have no value at all (which is different from
having an empty value) if there is no =
separator in the entry.
Implementations§
source§impl TxtRecord
impl TxtRecord
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty TxtRecord
with the specified capacity.
The inserting operations will still reallocate if necessary.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more bytes to be
used by inserting operations.
Each entry requires 1 byte for the total length, the length
of the key for the key; if there is a value 1 byte for the
separator =
and the length of the value for the value.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the TxtRecord
contains no elements (both in
bytes and key-value entries).
sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
if not empty this returns valid TXT RDATA, otherwise just an empty slice.
sourcepub fn rdata(&self) -> &[u8] ⓘ
pub fn rdata(&self) -> &[u8] ⓘ
always returns valid TXT RDATA; when the container is empty it
will return a TXT record with a single empty string (i.e.
&[0x00]
).
sourcepub fn iter(&self) -> TxtRecordIter<'_> ⓘ
pub fn iter(&self) -> TxtRecordIter<'_> ⓘ
Iterate over all (key, value)
pairs.
sourcepub fn get(&self, key: &[u8]) -> Option<Option<&[u8]>>
pub fn get(&self, key: &[u8]) -> Option<Option<&[u8]>>
Get value for entry with given key
Returns None
if there is no such entry, Some(None)
if the
entry exists but has no value, and Some(Some(value))
if the
entry exists and has a value.
sourcepub fn set(
&mut self,
key: &[u8],
value: Option<&[u8]>
) -> Result<(), TxtRecordError>
pub fn set(
&mut self,
key: &[u8],
value: Option<&[u8]>
) -> Result<(), TxtRecordError>
Insert or update the entry with key
to have the given value or on value
sourcepub fn set_no_value(&mut self, key: &[u8]) -> Result<(), TxtRecordError>
pub fn set_no_value(&mut self, key: &[u8]) -> Result<(), TxtRecordError>
Insert or update the entry with key
to have no value