Struct ServiceResolver

Source
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

Source

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.

Source

pub fn new_with_timeout(timeout: Duration) -> Self

Create a new ServiceResolver with a timeout.

Source

pub fn set_unchecked(&mut self) -> &mut Self

Disable checking if services came from a browser

Source

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

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

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

Trait Implementations§

Source§

impl Debug for ServiceResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServiceResolver

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.