psp_net/traits/
dns.rs

1#![allow(clippy::module_name_repetitions)]
2
3use core::fmt::Debug;
4
5use alloc::string::String;
6
7use core::net::SocketAddr;
8use psp::sys::in_addr;
9
10/// Trait for resolving hostnames
11///
12/// A type implementing this trait can resolve a hostname to an IP address.
13///
14pub trait ResolveHostname {
15    type Error: Debug;
16    /// Resolve a hostname to an IP address
17    ///
18    /// # Errors
19    /// An error will be returned if the hostname could not be resolved.
20    fn resolve_hostname(&mut self, hostname: &str) -> Result<SocketAddr, Self::Error>;
21}
22
23/// Trait for resolving IP addresses
24///
25/// A type implementing this trait can resolve an IP address to a hostname.
26pub trait ResolveAddr {
27    type Error: Debug;
28    /// Resolve an IP address to a hostname
29    ///
30    /// # Errors
31    /// An error will be returned if the IP address could not be resolved.
32    fn resolve_addr(&mut self, addr: in_addr) -> Result<String, Self::Error>;
33}
34
35/// Trait for resolving hostnames and IP addresses.
36///
37/// This trait combines [`ResolveHostname`] and [`ResolveAddr`].
38pub trait DnsResolver: ResolveHostname + ResolveAddr {}