pub struct DnsResolver { /* private fields */ }Expand description
A TTL-aware DNS resolver wrapping hickory_resolver::TokioResolver.
Configured with explicit name servers (the system resolver is not
used by default). resolve_a returns (IpAddr, ttl) pairs; resolve_srv
returns (IpAddr, port, ttl) triples.
Implementations§
Source§impl DnsResolver
impl DnsResolver
Sourcepub fn new(name_servers: &[String]) -> Self
pub fn new(name_servers: &[String]) -> Self
Build a resolver that queries the given name server addresses
(e.g. ["127.0.0.1:5353"]). An empty list falls back to the
SYSTEM resolver configuration when one is readable (container
deployments: Docker/Kubernetes embedded DNS), and to the default
public resolvers otherwise (see [system_nameservers]).
Sourcepub async fn resolve_a(
&self,
hostname: &str,
) -> Result<Vec<(IpAddr, u32)>, String>
pub async fn resolve_a( &self, hostname: &str, ) -> Result<Vec<(IpAddr, u32)>, String>
Resolve A records for hostname, returning (IpAddr, ttl) pairs.
The TTL is the minimum TTL across all returned records (the
earliest-expiring record governs the refresh interval). Returns an
empty vec if the hostname resolves to no A records.
Sourcepub async fn resolve_ip(
&self,
hostname: &str,
) -> Result<Vec<(IpAddr, u32)>, String>
pub async fn resolve_ip( &self, hostname: &str, ) -> Result<Vec<(IpAddr, u32)>, String>
Resolve both A and AAAA records for hostname (dual-stack), returning
(IpAddr, ttl) pairs. This is the dial-path resolution primitive:
lookup_ip short-circuits IP-literal inputs (no DNS), consults the
system hosts file (so localhost and any /etc/hosts entry resolves
without a network round-trip), and falls back to the configured name
servers for real hostnames. The TTL is the minimum across all
returned records (the earliest-expiring record governs caching).
Returns an empty vec if the hostname resolves to no addresses.
Sourcepub async fn resolve_srv(
&self,
hostname: &str,
) -> Result<Vec<(IpAddr, u16, u32)>, String>
pub async fn resolve_srv( &self, hostname: &str, ) -> Result<Vec<(IpAddr, u16, u32)>, String>
Resolve SRV records for hostname, returning
(IpAddr, port, ttl) triples. The resolver recursively resolves
each SRV target to an IP. The TTL is the minimum TTL across all
returned records. Returns an empty vec if the hostname resolves
to no SRV records.
Auto Trait Implementations§
impl Freeze for DnsResolver
impl !RefUnwindSafe for DnsResolver
impl Send for DnsResolver
impl Sync for DnsResolver
impl Unpin for DnsResolver
impl !UnwindSafe for DnsResolver
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more