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

source

pub fn new() -> Self

Constructs a new, empty TxtRecord.

source

pub fn parse_vec(data: Vec<u8>) -> Option<Self>

Parse binary blob as TXT RDATA

Same as parse but takes ownership of buffer.

source

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.

source

pub fn with_capacity(capacity: usize) -> Self

Constructs a new, empty TxtRecord with the specified capacity.

The inserting operations will still reallocate if necessary.

source

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.

source

pub fn is_empty(&self) -> bool

Returns true if the TxtRecord contains no elements (both in bytes and key-value entries).

source

pub fn clear(&mut self)

Clears the TxtRecord, removing all entries.

source

pub fn data(&self) -> &[u8]

if not empty this returns valid TXT RDATA, otherwise just an empty slice.

source

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]).

source

pub fn iter(&self) -> TxtRecordIter<'_>

Iterate over all (key, value) pairs.

source

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.

source

pub fn remove(&mut self, key: &[u8])

Remove entry with given key (if it exists)

source

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

source

pub fn set_no_value(&mut self, key: &[u8]) -> Result<(), TxtRecordError>

Insert or update the entry with key to have no value

source

pub fn set_value( &mut self, key: &[u8], value: &[u8], ) -> Result<(), TxtRecordError>

Insert or update the entry with key to have the given value

Trait Implementations§

source§

impl Clone for TxtRecord

source§

fn clone(&self) -> TxtRecord

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for TxtRecord

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> IntoIterator for &'a TxtRecord

source§

type IntoIter = TxtRecordIter<'a>

Which kind of iterator are we turning this into?
source§

type Item = (&'a [u8], Option<&'a [u8]>)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.