Struct postgres_inet::MaskedIpAddr
[−]
[src]
pub struct MaskedIpAddr { /* fields omitted */ }
An IP address with a netmask.
Methods
impl MaskedIpAddr
[src]
pub fn new<I: Into<IpAddr>>(addr: I, mask: u8) -> MaskedIpAddr
[src]
Creates a new MaskedIpAddr
from components.
Panics
Panics if the netmask 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 netmask(&self) -> u8
[src]
Returns the contained netmask.
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 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 Copy for MaskedIpAddr
[src]
impl Clone for MaskedIpAddr
[src]
fn clone(&self) -> MaskedIpAddr
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for MaskedIpAddr
[src]
impl PartialEq for MaskedIpAddr
[src]
fn eq(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests for !=
.
impl Hash for MaskedIpAddr
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for MaskedIpAddr
[src]
fn partial_cmp(&self, __arg_0: &MaskedIpAddr) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &MaskedIpAddr) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for MaskedIpAddr
[src]
fn cmp(&self, __arg_0: &MaskedIpAddr) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl From<Ipv4Addr> for MaskedIpAddr
[src]
fn from(ipv4: Ipv4Addr) -> MaskedIpAddr
[src]
Performs the conversion.
impl From<Ipv6Addr> for MaskedIpAddr
[src]
fn from(ipv6: Ipv6Addr) -> MaskedIpAddr
[src]
Performs the conversion.
impl From<IpAddr> for MaskedIpAddr
[src]
fn from(ip: IpAddr) -> MaskedIpAddr
[src]
Performs the conversion.
impl From<MaskedIpAddr> for IpAddr
[src]
fn from(mip: MaskedIpAddr) -> IpAddr
[src]
Performs the conversion.
impl From<[u8; 4]> for MaskedIpAddr
[src]
impl From<[u8; 16]> for MaskedIpAddr
[src]
impl From<[u16; 8]> for MaskedIpAddr
[src]
impl Display for MaskedIpAddr
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Debug for MaskedIpAddr
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl FromSql for MaskedIpAddr
[src]
fn from_sql(
_: &Type,
raw: &[u8]
) -> Result<Self, Box<Error + Sync + Send + 'static>>
[src]
_: &Type,
raw: &[u8]
) -> Result<Self, Box<Error + Sync + Send + 'static>>
Creates a new value of this type from a buffer of data of the specified Postgres Type
in its binary format. Read more
fn accepts(ty: &Type) -> bool
[src]
Determines if a value of this type can be created from the specified Postgres Type
. Read more
fn from_sql_null(ty: &Type) -> Result<Self, Box<Error + 'static + Send + Sync>>
Creates a new value of this type from a NULL
SQL value. Read more
fn from_sql_nullable(
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<Error + 'static + Send + Sync>>
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<Error + 'static + Send + Sync>>
A convenience function that delegates to from_sql
and from_sql_null
depending on the value of raw
. Read more
impl ToSql for MaskedIpAddr
[src]
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
[src]
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
Converts the value of self
into the binary format of the specified Postgres Type
, appending it to out
. Read more
fn accepts(ty: &Type) -> bool
Determines if a value of this type can be converted to the specified Postgres Type
. Read more
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
An adaptor method used internally by Rust-Postgres. Read more