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