[−][src]Struct postgres_inet::MaskedIpAddr
An IP address, if necessary in CIDR notation.
Methods
impl MaskedIpAddr
[src]
pub fn new<I: Into<IpAddr>>(addr: I, cidr: u8) -> MaskedIpAddr
[src]
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);
pub fn is_unspecified(&self) -> bool
[src]
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());
pub fn is_loopback(&self) -> bool
[src]
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());
pub fn is_multicast(&self) -> bool
[src]
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());
pub fn is_ipv4(&self) -> bool
[src]
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());
pub fn is_ipv6(&self) -> bool
[src]
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());
pub fn address(&self) -> IpAddr
[src]
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);
pub fn cidr(&self) -> u8
[src]
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);
pub fn netmask(&self) -> u8
[src]
Supported because of historical (and wrong) use of netmask instead of CIDR. Use MaskedIpAddr::cidr instead.
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);
pub fn subnet_mask(&self) -> u128
[src]
Returns the subnet mask, calculated from the CIDR.
pub fn into_inner(self) -> (IpAddr, u8)
[src]
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
impl Clone for MaskedIpAddr
[src]
fn clone(&self) -> MaskedIpAddr
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for MaskedIpAddr
[src]
impl Debug for MaskedIpAddr
[src]
impl Display for MaskedIpAddr
[src]
impl Eq for MaskedIpAddr
[src]
impl From<[u16; 8]> for MaskedIpAddr
[src]
impl From<[u8; 16]> for MaskedIpAddr
[src]
impl From<[u8; 4]> for MaskedIpAddr
[src]
impl From<IpAddr> for MaskedIpAddr
[src]
fn from(ip: IpAddr) -> MaskedIpAddr
[src]
impl From<Ipv4Addr> for MaskedIpAddr
[src]
fn from(ipv4: Ipv4Addr) -> MaskedIpAddr
[src]
impl From<Ipv6Addr> for MaskedIpAddr
[src]
fn from(ipv6: Ipv6Addr) -> MaskedIpAddr
[src]
impl From<MaskedIpAddr> for IpAddr
[src]
fn from(mip: MaskedIpAddr) -> IpAddr
[src]
impl<'_> FromSql<'_> for MaskedIpAddr
[src]
fn from_sql(
_: &Type,
raw: &[u8]
) -> Result<Self, Box<dyn Error + Sync + Send + 'static>>
[src]
_: &Type,
raw: &[u8]
) -> Result<Self, Box<dyn Error + Sync + Send + 'static>>
fn accepts(ty: &Type) -> bool
[src]
fn from_sql_null(
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
fn from_sql_nullable(
ty: &Type,
raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]
ty: &Type,
raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
impl FromStr for MaskedIpAddr
[src]
type Err = MaskedIpAddrParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for MaskedIpAddr
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for MaskedIpAddr
[src]
fn cmp(&self, other: &MaskedIpAddr) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<MaskedIpAddr> for MaskedIpAddr
[src]
fn eq(&self, other: &MaskedIpAddr) -> bool
[src]
fn ne(&self, other: &MaskedIpAddr) -> bool
[src]
impl PartialOrd<MaskedIpAddr> for MaskedIpAddr
[src]
fn partial_cmp(&self, other: &MaskedIpAddr) -> Option<Ordering>
[src]
fn lt(&self, other: &MaskedIpAddr) -> bool
[src]
fn le(&self, other: &MaskedIpAddr) -> bool
[src]
fn gt(&self, other: &MaskedIpAddr) -> bool
[src]
fn ge(&self, other: &MaskedIpAddr) -> bool
[src]
impl StructuralEq for MaskedIpAddr
[src]
impl StructuralPartialEq for MaskedIpAddr
[src]
impl ToSql for MaskedIpAddr
[src]
Auto Trait Implementations
impl RefUnwindSafe for MaskedIpAddr
impl Send for MaskedIpAddr
impl Sync for MaskedIpAddr
impl Unpin for MaskedIpAddr
impl UnwindSafe for MaskedIpAddr
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> FromSqlOwned for T where
T: FromSql<'a>,
[src]
T: FromSql<'a>,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,