pub struct ServiceResolver { /* private fields */ }
Expand description
ServiceResolver
is used resolve a service obtained from a
ServiceBrowser
. Browsing does not obtain all
information about a service, for example it doesn’t include port
information, and resolving the service will fill this information in.
§Note
This should be used only with services from a browse operation to ensure the interface and domain are set correctly.
§Examples
let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
let mut services = browser
.timeout(tokio::time::Duration::from_secs(2))
.browse()?;
while let Some(Ok(v)) = services.recv().await {
let resolved_service = async_zeroconf::ServiceResolver::r(&v).await?;
println!("Service = {}", resolved_service);
}
Implementations§
Source§impl ServiceResolver
impl ServiceResolver
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ServiceResolver
with the default settings.
The operation will have no timeout and it will check if the service to
be resolved was from a browser.
Sourcepub fn new_with_timeout(timeout: Duration) -> Self
pub fn new_with_timeout(timeout: Duration) -> Self
Create a new ServiceResolver
with a timeout.
Sourcepub fn set_unchecked(&mut self) -> &mut Self
pub fn set_unchecked(&mut self) -> &mut Self
Disable checking if services came from a browser
Sourcepub async fn r(service: &Service) -> Result<Service, ZeroconfError>
pub async fn r(service: &Service) -> Result<Service, ZeroconfError>
Static method to resolve the specified Service
, the service must have
been produced from a ServiceBrowser
to ensure
that the required information for the resolve operation is available.
§Examples
let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
let mut services = browser
.timeout(tokio::time::Duration::from_secs(2))
.browse()?;
while let Some(Ok(service)) = services.recv().await {
let resolved = async_zeroconf::ServiceResolver::r(&service).await?;
println!("Service = {}", resolved);
}
Sourcepub async fn resolve(&self, service: &Service) -> Result<Service, ZeroconfError>
pub async fn resolve(&self, service: &Service) -> Result<Service, ZeroconfError>
Resolve the specified Service
using this ServiceResolver
. This does
not consume the ServiceResolver
so more services can be resolved
using the same settings.
§Examples
let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
let mut services = browser
.timeout(tokio::time::Duration::from_secs(2))
.browse()?;
let resolver = async_zeroconf::ServiceResolver::new();
while let Some(Ok(service)) = services.recv().await {
let resolved = resolver.resolve(&service).await?;
println!("Service = {}", resolved);
}
Sourcepub async fn resolve_task(
&self,
service: &Service,
) -> Result<(impl Future<Output = Result<Service, ZeroconfError>>, impl ProcessTask), ZeroconfError>
pub async fn resolve_task( &self, service: &Service, ) -> Result<(impl Future<Output = Result<Service, ZeroconfError>>, impl ProcessTask), ZeroconfError>
Resolve the specified Service
using this ServiceResolver
. The
returned ProcessTask
future must be awaited to process events
associated with the browser.
If the resolve operation can be constructed, this will return a future which will produce the result of the resolve operation and a task which should be awaited on to handle any events associated with the resolving.
§Note
This method is intended if more control is needed over how the task
is spawned. ServiceResolver::resolve
will automatically spawn the
task.
§Examples
let mut browser = async_zeroconf::ServiceBrowserBuilder::new("_http._tcp");
let mut services = browser
.timeout(tokio::time::Duration::from_secs(2))
.browse()?;
let resolver = async_zeroconf::ServiceResolver::new();
while let Some(Ok(service)) = services.recv().await {
if let Ok((future, task)) = resolver.resolve_task(&service).await {
tokio::spawn(task);
let resolved = future.await?;
println!("Service = {}", resolved);
}
}