Skip to main content

ServiceResolverBuilder

Struct ServiceResolverBuilder 

Source
pub struct ServiceResolverBuilder { /* private fields */ }
Expand description

Builder for a one-shot DNS-SD resolve of a single, already-known service instance.

Where ServiceBrowserBuilder discovers instances over time, this resolves one named instance now — mapping the identity fields from a previous browse BrowseEvent::Found (or BrowseEvent::Removed) event back to a connectable DiscoveredService. Its main use is as a liveness probe: a dead instance fails with ServiceBrowseError::ResolveFailed rather than hanging, so consumers can re-confirm services they haven’t heard from recently and drop the ones that repeatedly fail.

This matters for the no-goodbye case (a host powered off, crashed, or that dropped off Wi-Fi without multicasting mDNS goodbye packets): the OS keeps the browse-driving PTR record until its (long) TTL expires, so no Removed event is delivered for a long time, yet a fresh resolve of the vanished instance fails promptly.

§Example

use mdns_sd_discovery::{ServiceBrowseError, ServiceResolverBuilder};

match ServiceResolverBuilder::new("My Web Server", "_http._tcp", "local")
    .resolve()
    .await
{
    Ok(svc) => println!("still alive at {}:{}", svc.host_name, svc.port),
    Err(ServiceBrowseError::ResolveFailed(name, _)) => println!("{name} is gone"),
    Err(err) => return Err(err.into()),
}

Implementations§

Source§

impl ServiceResolverBuilder

Source

pub fn new( name: impl AsRef<str>, service_type: impl AsRef<str>, domain: impl AsRef<str>, ) -> Self

Initializes a builder to resolve the instance identified by name, service_type (e.g. _http._tcp) and domain (e.g. local).

These are exactly the name, service_type and domain fields reported by a browse event.

Source

pub fn interface_index(&mut self, index: NonZeroU32) -> &mut Self

Restricts the resolve to a single interface (the index reported on the originating browse event, via DiscoveredService::interface_index).

When unset (the default) the instance is resolved on all interfaces.

Source

pub fn timeout(&mut self, timeout: Duration) -> &mut Self

Bounds how long resolve may take before failing with ServiceBrowseError::ResolveFailed.

This is what makes the resolve usable as a liveness probe: without it, resolving a vanished instance is only bounded by the platform default (on Linux, the D-Bus method timeout of roughly 25 s). Set a shorter timeout to fail faster; the platform default still applies as a ceiling.

Source

pub async fn resolve(&self) -> Result<DiscoveredService, ServiceBrowseError>

Resolves the instance, returning a connectable DiscoveredService.

Returns ServiceBrowseError::ResolveFailed if the instance no longer responds (or the configured timeout elapses first).

Trait Implementations§

Source§

impl Clone for ServiceResolverBuilder

Source§

fn clone(&self) -> ServiceResolverBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServiceResolverBuilder

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more