rama-net 0.3.0

rama network types and utilities
Documentation
use rama_core::extensions::Extension;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Extension)]
#[extension(tags(net))]
/// Enum representing the IP modes that can be used by the DNS resolver.
pub enum DnsResolveIpMode {
    #[default]
    Dual,
    SingleIpV4,
    SingleIpV6,
    DualPreferIpV4,
}

impl DnsResolveIpMode {
    /// checks if IPv4 is supported in current mode
    #[must_use]
    pub fn ipv4_supported(&self) -> bool {
        matches!(self, Self::Dual | Self::SingleIpV4 | Self::DualPreferIpV4)
    }

    /// checks if IPv6 is supported in current mode
    #[must_use]
    pub fn ipv6_supported(&self) -> bool {
        matches!(self, Self::Dual | Self::SingleIpV6 | Self::DualPreferIpV4)
    }
}
/// Mode for establishing a connection.
///
/// Classification is by wire family: an IPv4-mapped IPv6 address
/// (`::ffff:a.b.c.d`, [RFC 4291, Section 2.5.5.2]) counts as IPv4,
/// so [`Self::Ipv6`] rejects it and [`Self::Ipv4`] accepts it.
///
/// [RFC 4291, Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Extension)]
#[extension(tags(net))]
pub enum ConnectIpMode {
    #[default]
    Dual,
    Ipv4,
    Ipv6,
}