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
impl TxtRecord
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &Vec<u8>)>
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);
}
Sourcepub fn iter_string(
&self,
) -> impl Iterator<Item = (&String, Result<&str, Utf8Error>)>
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)
}
}
Sourcepub fn iter_string_lossy(&self) -> impl Iterator<Item = (&String, &str)>
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);
}
Sourcepub fn validate(&self) -> Result<(), ZeroconfError>
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());
Trait Implementations§
impl Eq for TxtRecord
impl StructuralPartialEq for 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
Mutably borrows from an owned value. Read more