pub struct MaskedIpAddr { /* private fields */ }
Expand description
An IP address, if necessary in CIDR notation.
Implementations§
Source§impl MaskedIpAddr
impl MaskedIpAddr
Sourcepub fn new<I: Into<IpAddr>>(addr: I, cidr: u8) -> MaskedIpAddr
pub fn new<I: Into<IpAddr>>(addr: I, cidr: u8) -> MaskedIpAddr
Creates a new MaskedIpAddr
from components.
Do not pass an addr
with bits set to the right of the netmask if you
intend to insert this into a postgres cidr
field.
§Panics
Panics if the CIDR is greater than 32 for an IPv4 address, or is greater than 128 for an IPv6 address.
§Examples
To represent an address:
let ip = Ipv4Addr::new(192, 0, 2, 142);
MaskedIpAddr::new(ip, 32);
To represent a network:
let network = Ipv6Addr::new(0x2001, 0x0DB8, 0, 0, 0, 0, 0, 0);
MaskedIpAddr::new(network, 32);
Sourcepub fn is_unspecified(&self) -> bool
pub fn is_unspecified(&self) -> bool
Returns true
for the special ‘unspecified’ address.
See the documentation for Ipv4Addr::is_unspecified
and
Ipv6Addr::is_unspecified
for more details.
§Examples
assert!(MaskedIpAddr::new(Ipv4Addr::new(0, 0, 0, 0), 32).is_unspecified());
assert!(MaskedIpAddr::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0), 128).is_unspecified());
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Returns true
if this is a loopback address.
See the documentation for Ipv4Addr::is_loopback
and
Ipv6Addr::is_loopback
for more details.
§Examples
assert!(MaskedIpAddr::new(Ipv4Addr::new(127, 0, 0, 1), 32).is_loopback());
assert!(MaskedIpAddr::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 128).is_loopback());
Sourcepub fn is_multicast(&self) -> bool
pub fn is_multicast(&self) -> bool
Returns true
if this is a multicast address.
See the documentation for Ipv4Addr::is_multicast
and
Ipv6Addr::is_multicast
for more details.
§Examples
assert!(MaskedIpAddr::new(Ipv4Addr::new(224, 254, 0, 0), 32).is_multicast());
assert!(MaskedIpAddr::new(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0), 128).is_multicast());
Sourcepub fn is_ipv4(&self) -> bool
pub fn is_ipv4(&self) -> bool
Returns true
if this address is an IPv4 address, and false
otherwise.
§Examples
assert!(MaskedIpAddr::new(Ipv4Addr::new(203, 0, 113, 6), 32).is_ipv4());
assert!(!MaskedIpAddr::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 128).is_ipv4());
Sourcepub fn is_ipv6(&self) -> bool
pub fn is_ipv6(&self) -> bool
Returns true
if this address is an IPv6 address, and false
otherwise.
§Examples
assert!(!MaskedIpAddr::new(Ipv4Addr::new(203, 0, 113, 6), 32).is_ipv6());
assert!(MaskedIpAddr::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 128).is_ipv6());
Sourcepub fn address(&self) -> IpAddr
pub fn address(&self) -> IpAddr
Returns the contained IP address.
§Examples
let ip = Ipv4Addr::new(192, 0, 2, 142);
assert_eq!(MaskedIpAddr::new(ip, 32).address(), ip);
let network = Ipv6Addr::new(0x2001, 0x0DB8, 0, 0, 0, 0, 0, 0);
assert_eq!(MaskedIpAddr::new(network, 32).address(), network);
Sourcepub fn cidr(&self) -> u8
pub fn cidr(&self) -> u8
Returns the contained CIDR.
§Examples
assert_eq!(MaskedIpAddr::new(Ipv4Addr::new(192, 0, 2, 142), 32).cidr(), 32);
assert_eq!(MaskedIpAddr::new(Ipv6Addr::new(0x2001, 0x0DB8, 0, 0, 0, 0, 0, 0), 64).cidr(), 64);
Sourcepub fn netmask(&self) -> u8
👎Deprecated since 0.15.2: Supported because of historical (and wrong) use of netmask instead of CIDR. Use MaskedIpAddr::cidr instead.
pub fn netmask(&self) -> u8
Returns the contained CIDR.
§Examples
assert_eq!(MaskedIpAddr::new(Ipv4Addr::new(192, 0, 2, 142), 32).netmask(), 32);
assert_eq!(MaskedIpAddr::new(Ipv6Addr::new(0x2001, 0x0DB8, 0, 0, 0, 0, 0, 0), 64).netmask(), 64);
Sourcepub fn subnet_mask(&self) -> u128
pub fn subnet_mask(&self) -> u128
Returns the subnet mask, calculated from the CIDR.
Sourcepub fn into_inner(self) -> (IpAddr, u8)
pub fn into_inner(self) -> (IpAddr, u8)
Consumes the MaskedIpAddr
, returning the IP address and netmask.
§Examples
let network = Ipv4Addr::new(198, 51, 100, 0);
assert_eq!(MaskedIpAddr::new(network, 24).into_inner(), (network.into(), 24));
Trait Implementations§
Source§impl Clone for MaskedIpAddr
impl Clone for MaskedIpAddr
Source§fn clone(&self) -> MaskedIpAddr
fn clone(&self) -> MaskedIpAddr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MaskedIpAddr
impl Debug for MaskedIpAddr
Source§impl Display for MaskedIpAddr
impl Display for MaskedIpAddr
Source§impl From<IpAddr> for MaskedIpAddr
impl From<IpAddr> for MaskedIpAddr
Source§fn from(ip: IpAddr) -> MaskedIpAddr
fn from(ip: IpAddr) -> MaskedIpAddr
Source§impl From<Ipv4Addr> for MaskedIpAddr
impl From<Ipv4Addr> for MaskedIpAddr
Source§fn from(ipv4: Ipv4Addr) -> MaskedIpAddr
fn from(ipv4: Ipv4Addr) -> MaskedIpAddr
Source§impl From<Ipv6Addr> for MaskedIpAddr
impl From<Ipv6Addr> for MaskedIpAddr
Source§fn from(ipv6: Ipv6Addr) -> MaskedIpAddr
fn from(ipv6: Ipv6Addr) -> MaskedIpAddr
Source§impl From<MaskedIpAddr> for IpAddr
impl From<MaskedIpAddr> for IpAddr
Source§fn from(mip: MaskedIpAddr) -> IpAddr
fn from(mip: MaskedIpAddr) -> IpAddr
Source§impl FromSql<'_> for MaskedIpAddr
impl FromSql<'_> for MaskedIpAddr
Source§fn from_sql(
_: &Type,
raw: &[u8],
) -> Result<Self, Box<dyn Error + Sync + Send + 'static>>
fn from_sql( _: &Type, raw: &[u8], ) -> Result<Self, Box<dyn Error + Sync + Send + 'static>>
Type
in its binary format. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type
.Source§impl FromStr for MaskedIpAddr
impl FromStr for MaskedIpAddr
Source§impl Hash for MaskedIpAddr
impl Hash for MaskedIpAddr
Source§impl Ord for MaskedIpAddr
impl Ord for MaskedIpAddr
Source§fn cmp(&self, other: &MaskedIpAddr) -> Ordering
fn cmp(&self, other: &MaskedIpAddr) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for MaskedIpAddr
impl PartialEq for MaskedIpAddr
Source§impl PartialOrd for MaskedIpAddr
impl PartialOrd for MaskedIpAddr
Source§impl ToSql for MaskedIpAddr
impl ToSql for MaskedIpAddr
Source§fn to_sql(
&self,
ty: &Type,
w: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn to_sql( &self, ty: &Type, w: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
self
into the binary format of the specified
Postgres Type
, appending it to out
. Read moreimpl Copy for MaskedIpAddr
impl Eq for MaskedIpAddr
impl StructuralPartialEq for MaskedIpAddr
Auto Trait Implementations§
impl Freeze for MaskedIpAddr
impl RefUnwindSafe for MaskedIpAddr
impl Send for MaskedIpAddr
impl Sync for MaskedIpAddr
impl Unpin for MaskedIpAddr
impl UnwindSafe for MaskedIpAddr
Blanket Implementations§
Source§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
Source§impl<T> BorrowToSql for Twhere
T: ToSql,
impl<T> BorrowToSql for Twhere
T: ToSql,
Source§fn borrow_to_sql(&self) -> &dyn ToSql
fn borrow_to_sql(&self) -> &dyn ToSql
self
as a ToSql
trait object.