Skip to main content

Discovery

Trait Discovery 

Source
pub trait Discovery: Send + Sync {
    // Required methods
    fn advertise(&self, service: ServiceAdvertisement) -> Result<()>;
    fn withdraw(&self, service_type: &str) -> Result<()>;
    fn browse(&self, service_type: &str) -> Result<Vec<DiscoveredServer>>;
}
Expand description

How a service is published and how remote ones are found.

A host implements this over its mDNS library of choice; the crate decides what the record contains and what an announcement obliges it to do, so the two stay in one place. The trait never reports a record it has not published: advertise returning Ok means a server can find the endpoint, and the whole server-initiated mode rests on that.

A client that advertises must not dial a server itself (connection.md, Server Initiated Connections). This crate enforces that: connect refuses a configuration that advertises.

Required Methods§

Source

fn advertise(&self, service: ServiceAdvertisement) -> Result<()>

Publishes service until its service type is withdrawn.

§Errors

Returns an error when the record could not be published. The client then refuses to start, because accepting connections nobody can find is not the mode it was asked for.

Source

fn withdraw(&self, service_type: &str) -> Result<()>

Withdraws the advertisement of service_type.

Called when the inbound listener closes: a record that outlives its listener points at a closed port. Withdrawing a type that was never advertised is not an error.

Source

fn browse(&self, service_type: &str) -> Result<Vec<DiscoveredServer>>

Returns the services currently advertised under service_type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§