Skip to main content

MdnsConfig

Struct MdnsConfig 

Source
pub struct MdnsConfig {
    pub query_interval: Duration,
    pub query_timeout: Option<Duration>,
    pub local_names: Vec<String>,
    pub local_ip: Option<IpAddr>,
}
Expand description

MdnsConfiguration for an mDNS connection.

Use the builder pattern to construct a configuration:

use rtc_mdns::MdnsConfig;
use std::time::Duration;

let config = MdnsConfig::new()
    .with_query_interval(Duration::from_millis(500))
    .with_local_names(vec!["myhost.local".to_string()]);

§Fields

  • query_interval: How often to retry unanswered queries (default: 1 second)
  • query_timeout: Maximum time to wait for a query answer (default: None - no timeout)
  • local_names: Names this connection will respond to (empty by default)
  • local_addr: IP address to advertise in responses (required for server mode)

Fields§

§query_interval: Duration

How often to retry unanswered queries.

When a query is started, it will be retried at this interval until either an answer is received or the query is cancelled.

Default: 1 second

§Example

use rtc_mdns::MdnsConfig;
use std::time::Duration;

// Retry queries every 500ms for faster discovery
let config = MdnsConfig::default()
    .with_query_interval(Duration::from_millis(500));
§query_timeout: Option<Duration>

Maximum time to wait for a query to be answered.

When set, queries that haven’t received an answer within this duration will emit MdnsEvent::QueryTimeout and be automatically cancelled.

When None, queries will retry indefinitely until answered or manually cancelled.

Default: None (no automatic timeout)

§Example

use rtc_mdns::MdnsConfig;
use std::time::Duration;

// Timeout queries after 5 seconds
let config = MdnsConfig::default()
    .with_query_timeout(Duration::from_secs(5));
§local_names: Vec<String>

Local names that this connection will respond to.

When an mDNS query arrives for any of these names, the connection will automatically generate a response with the configured local_addr.

Names should be in .local format (e.g., "myhost.local"). Trailing dots are optional and will be normalized internally.

Default: empty (no names to respond to)

§Example

use rtc_mdns::MdnsConfig;

let config = MdnsConfig::default()
    .with_local_names(vec![
        "mydevice.local".to_string(),
        "printer.local".to_string(),
    ]);
§local_ip: Option<IpAddr>

Local address to advertise in mDNS responses.

This IP address will be included in A record responses when queries for local_names are received.

Required if local_names is non-empty, otherwise responses cannot be generated.

Default: None

§Example

use rtc_mdns::MdnsConfig;
use std::net::{IpAddr, Ipv4Addr};

let config = MdnsConfig::default()
    .with_local_names(vec!["myhost.local".to_string()])
    .with_local_ip(
        IpAddr::V4(Ipv4Addr::new(192, 168, 1, 42)),
    );

Implementations§

Source§

impl MdnsConfig

Source

pub fn new() -> Self

Create a new configuration with default values.

Equivalent to MdnsConfig::default().

§Example
use rtc_mdns::MdnsConfig;

let config = MdnsConfig::new();
Source

pub fn with_query_interval(self, interval: Duration) -> Self

Set the query retry interval.

Queries will be retried at this interval until answered or cancelled. A value of zero will use the default interval (1 second).

§Arguments
  • interval - Duration between query retries
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;

let config = MdnsConfig::default()
    .with_query_interval(Duration::from_millis(250));
Source

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

Set the query timeout.

When set, queries that don’t receive an answer within this duration will emit MdnsEvent::QueryTimeout and be automatically removed from the pending list.

§Arguments
  • timeout - Maximum duration to wait for a query answer
§Example
use rtc_mdns::MdnsConfig;
use std::time::Duration;

// Queries will timeout after 5 seconds
let config = MdnsConfig::default()
    .with_query_timeout(Duration::from_secs(5));

// Combined with retry interval: retry every 500ms, give up after 3s
let config = MdnsConfig::default()
    .with_query_interval(Duration::from_millis(500))
    .with_query_timeout(Duration::from_secs(3));
Source

pub fn with_local_names(self, names: Vec<String>) -> Self

Set the local names to respond to.

When mDNS queries for these names are received, the connection will automatically generate responses with the configured local_addr.

§Arguments
  • names - List of hostnames (e.g., ["myhost.local"])
§Example
use rtc_mdns::MdnsConfig;

let config = MdnsConfig::default()
    .with_local_names(vec!["server.local".to_string()]);
Source

pub fn with_local_ip(self, local_ip: IpAddr) -> Self

Set the local address to advertise in responses.

This address will be included in A record responses. The port is typically 5353 for mDNS.

§Arguments
  • addr - Socket address containing the IP to advertise
§Example
use rtc_mdns::MdnsConfig;
use std::net::{IpAddr, Ipv4Addr};

let config = MdnsConfig::default()
    .with_local_ip(
        IpAddr::V4(Ipv4Addr::new(10, 0, 0, 5)),
    );

Trait Implementations§

Source§

impl Clone for MdnsConfig

Source§

fn clone(&self) -> MdnsConfig

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 MdnsConfig

Source§

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

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

impl Default for MdnsConfig

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V