Skip to main content

TxtRecord

Struct TxtRecord 

Source
pub struct TxtRecord { /* private fields */ }
Expand description

Struct containing the entries for TXT records associated with a service

§Examples

let mut txt = async_zeroconf::TxtRecord::new();
txt.add("key1".to_string(), "value1".to_string());
txt.add("key2".to_string(), "value2".to_string());
let service_ref = async_zeroconf::Service::new_with_txt("Server", "_http._tcp", 80, txt)
                      .publish().await?;

Implementations§

Source§

impl TxtRecord

Source

pub fn new() -> Self

Create a new TXT record collection

Source

pub fn add(&mut self, k: String, v: String)

Add an entry from a string

Source

pub fn add_vec(&mut self, k: String, v: Vec<u8>)

Add an entry from a slice of u8’s

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &Vec<u8>)>

Get Iterator

§Examples
let mut txt = async_zeroconf::TxtRecord::new();
txt.add("key".to_string(), "value".to_string());
// Iterator
let iter = txt.iter();
for (k, v) in iter {
    println!("{}, {:?}", k, v);
}
Source

pub fn iter_string( &self, ) -> impl Iterator<Item = (&String, Result<&str, Utf8Error>)>

Get Iterator including conversion to string. As the conversion to a UTF-8 string could fail the value is returned as a Result.

§Examples
let mut txt = async_zeroconf::TxtRecord::new();
txt.add("key".to_string(), "value".to_string());
// String iterator
let iter = txt.iter_string();
for (k, v) in iter {
    match v {
        Ok(v) => println!("{}, {}", k, v),
        Err(_) => println!("{} not valid UTF-8", k)
    }
}
Source

pub fn iter_string_lossy(&self) -> impl Iterator<Item = (&String, &str)>

Get Iterator including conversion to string. If the conversion to UTF-8 fails, ‘�’ will be returned instead.

§Examples
let mut txt = async_zeroconf::TxtRecord::new();
txt.add("key".to_string(), "value".to_string());
// String iterator
let iter = txt.iter_string_lossy();
for (k, v) in iter {
    println!("{}, {}", k, v);
}
Source

pub fn validate(&self) -> Result<(), ZeroconfError>

Validate if this TXT record collection contains all valid values. This checks that the key is 9 characters or less, the value is 255 characters or less and that the key only has printable ASCII characters excluding ‘=’.

§Examples
let mut valid_txt = async_zeroconf::TxtRecord::new();
valid_txt.add("key".to_string(), "value".to_string());
assert!(valid_txt.validate().is_ok());

let mut invalid_txt = async_zeroconf::TxtRecord::new();
invalid_txt.add("k\0".to_string(), "value".to_string());
assert!(invalid_txt.validate().is_err());
Source

pub fn is_empty(&self) -> bool

Empty if no records are associated

Trait Implementations§

Source§

impl Clone for TxtRecord

Source§

fn clone(&self) -> TxtRecord

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TxtRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TxtRecord

Source§

fn default() -> Self

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

impl Display for TxtRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TxtRecord

Source§

impl PartialEq for TxtRecord

Source§

fn eq(&self, other: &TxtRecord) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TxtRecord

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.