pub struct ServiceInfo { /* private fields */ }Expand description
Complete info about a Service Instance.
We can construct some PTR, one SRV and one TXT record from this info, as well as A (IPv4 Address) and AAAA (IPv6 Address) records.
Implementations§
Source§impl ServiceInfo
impl ServiceInfo
Sourcepub fn new<Ip: AsIpAddrs, P: IntoTxtProperties>(
ty_domain: &str,
my_name: &str,
host_name: &str,
ip: Ip,
port: u16,
properties: P,
) -> Result<Self>
pub fn new<Ip: AsIpAddrs, P: IntoTxtProperties>( ty_domain: &str, my_name: &str, host_name: &str, ip: Ip, port: u16, properties: P, ) -> Result<Self>
Creates a new service info.
ty_domain is the service type and the domain label, for example
“_my-service._udp.local.”.
my_name is the instance name, without the service type suffix.
host_name is the “host” in the context of DNS. It is used as the “name”
in the address records (i.e. TYPE_A and TYPE_AAAA records). It means that
for the same hostname in the same local network, the service resolves in
the same addresses. Be sure to check it if you see unexpected addresses resolved.
properties can be None or key/value string pairs, in a type that
implements IntoTxtProperties trait. It supports:
HashMap<String, String>Option<HashMap<String, String>>- slice of tuple:
&[(K, V)]whereKandVarestd::string::ToString.
Note: The maximum length of a single property string is 255, Property that exceed the length are truncated.
len(key + value) < u8::MAX
ip can be one or more IP addresses, in a type that implements
AsIpAddrs trait. It supports:
- Single IPv4:
"192.168.0.1" - Single IPv6:
"2001:0db8::7334" - Multiple IPv4 separated by comma:
"192.168.0.1,192.168.0.2" - Multiple IPv6 separated by comma:
"2001:0db8::7334,2001:0db8::7335" - A slice of IPv4:
&["192.168.0.1", "192.168.0.2"] - A slice of IPv6:
&["2001:0db8::7334", "2001:0db8::7335"] - A mix of IPv4 and IPv6:
"192.168.0.1,2001:0db8::7334" - All the above formats with IpAddr or
Stringinstead of&str.
The host TTL and other TTL are set to default values.
Sourcepub const fn enable_addr_auto(self) -> Self
pub const fn enable_addr_auto(self) -> Self
Indicates that the library should automatically update the addresses of this service, when IP address(es) are added or removed on the host.
Sourcepub const fn is_addr_auto(&self) -> bool
pub const fn is_addr_auto(&self) -> bool
Returns if the service’s addresses will be updated automatically when the host IP addrs change.
Sourcepub fn set_requires_probe(&mut self, enable: bool)
pub fn set_requires_probe(&mut self, enable: bool)
Set whether this service info requires name probing for potential name conflicts.
By default, it is true (i.e. requires probing) for every service info. You
set it to false only when you are sure there are no conflicts, or for testing purposes.
Sourcepub const fn requires_probe(&self) -> bool
pub const fn requires_probe(&self) -> bool
Returns whether this service info requires name probing for potential name conflicts.
By default, it returns true for every service info.
Sourcepub fn get_type(&self) -> &str
pub fn get_type(&self) -> &str
Returns the service type including the domain label.
For example: “_my-service._udp.local.”.
Sourcepub const fn get_subtype(&self) -> &Option<String>
pub const fn get_subtype(&self) -> &Option<String>
Returns the service subtype including the domain label, if subtype has been defined.
For example: “_printer._sub._http._tcp.local.”.
Sourcepub fn get_fullname(&self) -> &str
pub fn get_fullname(&self) -> &str
Returns a reference of the service fullname.
This is useful, for example, in unregister.
Sourcepub const fn get_properties(&self) -> &TxtProperties
pub const fn get_properties(&self) -> &TxtProperties
Returns the properties from TXT records.
Sourcepub fn get_property(&self, key: &str) -> Option<&TxtProperty>
pub fn get_property(&self, key: &str) -> Option<&TxtProperty>
Returns a property for a given key, where key is
case insensitive.
Returns None if key does not exist.
Sourcepub fn get_property_val(&self, key: &str) -> Option<Option<&[u8]>>
pub fn get_property_val(&self, key: &str) -> Option<Option<&[u8]>>
Returns a property value for a given key, where key is
case insensitive.
Returns None if key does not exist.
Sourcepub fn get_property_val_str(&self, key: &str) -> Option<&str>
pub fn get_property_val_str(&self, key: &str) -> Option<&str>
Returns a property value string for a given key, where key is
case insensitive.
Returns None if key does not exist.
Sourcepub fn get_hostname(&self) -> &str
pub fn get_hostname(&self) -> &str
Returns the service’s hostname.
Sourcepub const fn get_addresses(&self) -> &HashSet<IpAddr>
pub const fn get_addresses(&self) -> &HashSet<IpAddr>
Returns the service’s addresses
Sourcepub fn get_addresses_v4(&self) -> HashSet<&Ipv4Addr>
pub fn get_addresses_v4(&self) -> HashSet<&Ipv4Addr>
Returns the service’s IPv4 addresses only.
Sourcepub const fn get_host_ttl(&self) -> u32
pub const fn get_host_ttl(&self) -> u32
Returns the service’s TTL used for SRV and Address records.
Sourcepub const fn get_other_ttl(&self) -> u32
pub const fn get_other_ttl(&self) -> u32
Returns the service’s TTL used for PTR and TXT records.
Sourcepub const fn get_priority(&self) -> u16
pub const fn get_priority(&self) -> u16
Returns the service’s priority used in SRV records.
Sourcepub const fn get_weight(&self) -> u16
pub const fn get_weight(&self) -> u16
Returns the service’s weight used in SRV records.
Sourcepub fn as_resolved_service(self) -> ResolvedService
pub fn as_resolved_service(self) -> ResolvedService
Consumes self and returns a resolved service, i.e. a lite version of ServiceInfo.
Trait Implementations§
Source§impl Clone for ServiceInfo
impl Clone for ServiceInfo
Source§fn clone(&self) -> ServiceInfo
fn clone(&self) -> ServiceInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more