Struct postgres_inet::MaskedIpAddr
[−]
[src]
pub struct MaskedIpAddr { /* fields omitted */ }
An IP address with a netmask.
Methods
impl MaskedIpAddr
[src]
fn new<I: Into<IpAddr>>(addr: I, mask: u8) -> MaskedIpAddr
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);
fn is_unspecified(&self) -> bool
Returns true for the special 'unspecified' address.
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());
fn is_loopback(&self) -> bool
Returns true if this is a loopback address.
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());
fn is_multicast(&self) -> bool
Returns true if this is a multicast address.
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());
fn into_inner(self) -> (IpAddr, u8)
Consumes the MaskedIpAddr
, returning the IP address and netmask.
Examples
let network = Ipv4Addr::new(198, 51, 100, 0); let (network_b, netmask) = MaskedIpAddr::new(network.clone(), 24).into_inner(); assert_eq!(network, network_b); assert_eq!(netmask, 24);
Trait Implementations
impl Clone for MaskedIpAddr
[src]
fn clone(&self) -> MaskedIpAddr
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Eq for MaskedIpAddr
[src]
impl PartialEq for MaskedIpAddr
[src]
fn eq(&self, __arg_0: &MaskedIpAddr) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &MaskedIpAddr) -> bool
This method tests for !=
.
impl Hash for MaskedIpAddr
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl PartialOrd for MaskedIpAddr
[src]
fn partial_cmp(&self, __arg_0: &MaskedIpAddr) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &MaskedIpAddr) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &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, __arg_0: &MaskedIpAddr) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &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]
fn cmp(&self, __arg_0: &MaskedIpAddr) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl From<Ipv4Addr> for MaskedIpAddr
[src]
fn from(ipv4: Ipv4Addr) -> MaskedIpAddr
Performs the conversion.
impl From<Ipv6Addr> for MaskedIpAddr
[src]
fn from(ipv6: Ipv6Addr) -> MaskedIpAddr
Performs the conversion.
impl From<IpAddr> for MaskedIpAddr
[src]
fn from(ip: IpAddr) -> MaskedIpAddr
Performs the conversion.
impl Display for MaskedIpAddr
[src]
impl Debug for MaskedIpAddr
[src]
impl FromSql for MaskedIpAddr
[src]
fn from_sql(_: &Type,
raw: &[u8])
-> Result<Self, Box<Error + Sync + Send + 'static>>
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
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>>
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>>
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>>
ty: &Type,
out: &mut Vec<u8>)
-> Result<IsNull, Box<Error + Sync + Send>>
An adaptor method used internally by Rust-Postgres. Read more