Struct async_zeroconf::TxtRecord[][src]

pub struct TxtRecord { /* fields omitted */ }
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

Create a new TXT record collection

Add an entry from a string

Add an entry from a slice of u8’s

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);
}

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)
    }
}

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);
}

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());

Empty if no records are associated

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.