Struct postgres_inet::MaskedIpAddr[][src]

pub struct MaskedIpAddr { /* fields omitted */ }
Expand description

An IP address, if necessary in CIDR notation.

Implementations

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);

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());

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());

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());

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());

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());

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);

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);
👎 Deprecated since 0.15.2:

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);

Returns the subnet mask, calculated from the CIDR.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more

Determines if a value of this type can be created from the specified Postgres Type. Read more

Creates a new value of this type from a NULL SQL value. Read more

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more

Determines if a value of this type can be converted to the specified Postgres Type. Read more

An adaptor method used internally by Rust-Postgres. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a reference to self as a ToSql trait object.

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.