Struct async_dnssd::TxtRecord
source · pub struct TxtRecord(/* private fields */);
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 parse_vec(data: Vec<u8>) -> Option<Self>
pub fn parse_vec(data: Vec<u8>) -> Option<Self>
Parse binary blob as TXT RDATA
Same as parse
but takes ownership of buffer.
sourcepub fn parse(data: &[u8]) -> Option<Self>
pub fn parse(data: &[u8]) -> Option<Self>
Parse some binary blob as TXT RDATA
A single empty string (encoded as 0x00
) gets decoded as “empty” TxtRecord
(i.e. the
reverse th rdata()
); an empty slice is treated the same, although it wouldn’t be valid
RDATA.
This only fails when the length of a chunk exceeds the remaining data.
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
Trait Implementations§
source§impl<'a> IntoIterator for &'a TxtRecord
impl<'a> IntoIterator for &'a TxtRecord
Auto Trait Implementations§
impl Freeze for TxtRecord
impl RefUnwindSafe for TxtRecord
impl Send for TxtRecord
impl Sync for TxtRecord
impl Unpin for TxtRecord
impl UnwindSafe for TxtRecord
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)