pub(super) mod tcp;
if_any_rt!(
mod io;
#[cfg(unix)]
mod uds;
);
if_all_rt! {
pub use tcp::tokio::TcpConnector;
#[cfg(unix)]
pub use uds::tokio::UnixConnector;
}
if_tokio_rt! {
pub use tcp::tokio::TcpConnector;
#[cfg(unix)]
pub use uds::tokio::UnixConnector;
}
if_compio_rt! {
pub use tcp::compio::TcpConnector;
#[cfg(unix)]
pub use uds::compio::UnixConnector;
}
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
#[derive(Debug, Clone, Hash, PartialEq, Eq, Default)]
pub(crate) struct SocketBindOptions {
#[cfg(any(
target_os = "illumos",
target_os = "ios",
target_os = "macos",
target_os = "solaris",
target_os = "tvos",
target_os = "visionos",
target_os = "watchos",
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
))]
pub interface: Option<std::borrow::Cow<'static, str>>,
pub ipv4_address: Option<Ipv4Addr>,
pub ipv6_address: Option<Ipv6Addr>,
}
impl SocketBindOptions {
#[cfg(any(
target_os = "android",
target_os = "fuchsia",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "solaris",
target_os = "tvos",
target_os = "visionos",
target_os = "watchos",
))]
#[inline]
pub fn set_interface<I>(&mut self, interface: I) -> &mut Self
where
I: Into<std::borrow::Cow<'static, str>>,
{
self.interface = Some(interface.into());
self
}
#[inline]
pub fn set_local_address<V>(&mut self, local_address: V)
where
V: Into<Option<IpAddr>>,
{
match local_address.into() {
Some(IpAddr::V4(a)) => {
self.ipv4_address = Some(a);
}
Some(IpAddr::V6(a)) => {
self.ipv6_address = Some(a);
}
_ => {}
};
}
#[inline]
pub fn set_local_addresses<V4, V6>(&mut self, ipv4_address: V4, ipv6_address: V6)
where
V4: Into<Option<Ipv4Addr>>,
V6: Into<Option<Ipv6Addr>>,
{
if let Some(addr) = ipv4_address.into() {
self.ipv4_address = Some(addr);
}
if let Some(addr) = ipv6_address.into() {
self.ipv6_address = Some(addr);
}
}
}