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
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());
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for TxtRecord
impl UnwindSafe for TxtRecord
Blanket Implementations
Mutably borrows from an owned value. Read more