Struct async_zeroconf::Service[][src]

pub struct Service { /* fields omitted */ }
Expand description

Struct representing a ZeroConf service. This should be created with all the information that should be associated with the service and then the publish method can be used to register the service. The ServiceRef returned from publish should be held for as long as the service should continue being advertised, once dropped the service will be deallocated.

Examples

Normally the default values of domain, host and interface don’t need to be changed.

let service_ref = async_zeroconf::Service::new("Server", "_http._tcp", 80)
                      .publish().await?;
// Service kept alive until service_ref dropped

These fields can be customised if required. More details are available in the DNSServiceRegister documentation.

let service_ref = async_zeroconf::Service::new("Server", "_http._tcp", 80)
                      .set_domain("local".to_string())
                      .set_host("localhost".to_string())
                      .publish().await?;
// Service kept alive until service_ref dropped

Implementations

Create a new Service, called name of type service_type that is listening on port port.

This must then be published with Service::publish to advertise the service.

Examples

// Create a service description
let service = async_zeroconf::Service::new("Web Server", "_http._tcp", 80);

Create a new Service, called name of type service_type that is listening on port port with the TXT records described by txt.

This must then be published with Service::publish to advertise the service.

Examples

// Create a TXT record collection
let mut txt = async_zeroconf::TxtRecord::new();
txt.add("version".to_string(), "0.1".to_string());
// Create a service description
let service = async_zeroconf::Service::new_with_txt("Web Server", "_http._tcp", 80, txt);

Set an interface to advertise the service on rather than all.

By default the service will be advertised on all interfaces.

Get this interface associated with this service

Prevent renaming of this service if there is a name collision.

By default the service will be automatically renamed.

Set the (optional) domain for the service.

If not specified, the default domain is used.

Get the domain of this service

Set the (optional) hostname for the service.

If not set, the hostname of the host will be used.

Get the name of the service

Get the type of the service

Get the port of the service

Add a TXT entry to the service

Publish the service, returns a ServiceRef which should be held to keep the service alive. Once the ServiceRef is dropped the service will be removed and deallocated.

Arguments

  • allow_rename - Allow the service to be automatically renamed if a service with the same name already exists

Examples

// Create a service description
let service = async_zeroconf::Service::new("Server", "_http._tcp", 80);
// Publish the service
let service_ref = service.publish().await?;
// Service kept alive until service_ref dropped

Publish the service, returns a ServiceRef which should be held to keep the service alive and a future which should be awaited on to respond to any events associated with keeping the service registered. Once the ServiceRef is dropped the service will be removed and deallocated.

Note

This method is intended if more control is needed over how the task is spawned. Service::publish will automatically spawn the task. The task should be spawned first to process events, and then the returned future waited on to collect any errors that occurred.

Examples

// Create a service description
let service = async_zeroconf::Service::new("Server", "_http._tcp", 80);
// Publish the service
let (service_ref, task, service_ok) = service.publish_task()?;
// Spawn the task to respond to events
tokio::spawn(task);
// Wait to confirm service started ok
service_ok.await?;
// Service kept alive until service_ref dropped

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.