Struct sqlx::types::ipnetwork::Ipv4Network[][src]

pub struct Ipv4Network { /* fields omitted */ }

Represents a network range where the IP addresses are of v4

Implementations

impl Ipv4Network[src]

pub fn new(addr: Ipv4Addr, prefix: u8) -> Result<Ipv4Network, IpNetworkError>[src]

Constructs a new Ipv4Network from any Ipv4Addr and a prefix denoting the network size.

If the prefix is larger than 32 this will return an IpNetworkError::InvalidPrefix.

pub fn with_netmask(
    netaddr: Ipv4Addr,
    netmask: Ipv4Addr
) -> Result<Ipv4Network, IpNetworkError>
[src]

Constructs a new Ipv4Network from a network address and a network mask.

If the netmask is not valid this will return an IpNetworkError::InvalidPrefix.

pub fn iter(self) -> Ipv4NetworkIterator[src]

Returns an iterator over Ipv4Network. Each call to next will return the next Ipv4Addr in the given network. None will be returned when there are no more addresses.

pub fn ip(self) -> Ipv4Addr[src]

pub fn prefix(self) -> u8[src]

pub fn is_subnet_of(self, other: Ipv4Network) -> bool[src]

Checks if the given Ipv4Network is a subnet of the other.

pub fn is_supernet_of(self, other: Ipv4Network) -> bool[src]

Checks if the given Ipv4Network is a supernet of the other.

pub fn overlaps(self, other: Ipv4Network) -> bool[src]

Checks if the given Ipv4Network is partly contained in other.

pub fn mask(self) -> Ipv4Addr[src]

Returns the mask for this Ipv4Network. That means the prefix most significant bits will be 1 and the rest 0

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "127.0.0.0".parse().unwrap();
assert_eq!(net.mask(), Ipv4Addr::new(255, 255, 255, 255));
let net: Ipv4Network = "127.0.0.0/16".parse().unwrap();
assert_eq!(net.mask(), Ipv4Addr::new(255, 255, 0, 0));

pub fn network(self) -> Ipv4Addr[src]

Returns the address of the network denoted by this Ipv4Network. This means the lowest possible IPv4 address inside of the network.

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "10.1.9.32/16".parse().unwrap();
assert_eq!(net.network(), Ipv4Addr::new(10, 1, 0, 0));

pub fn broadcast(self) -> Ipv4Addr[src]

Returns the broadcasting address of this Ipv4Network. This means the highest possible IPv4 address inside of the network.

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "10.9.0.32/16".parse().unwrap();
assert_eq!(net.broadcast(), Ipv4Addr::new(10, 9, 255, 255));

pub fn contains(self, ip: Ipv4Addr) -> bool[src]

Checks if a given Ipv4Addr is in this Ipv4Network

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "127.0.0.0/24".parse().unwrap();
assert!(net.contains(Ipv4Addr::new(127, 0, 0, 70)));
assert!(!net.contains(Ipv4Addr::new(127, 0, 1, 70)));

pub fn size(self) -> u32[src]

Returns number of possible host addresses in this Ipv4Network.

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "10.1.0.0/16".parse().unwrap();
assert_eq!(net.size(), 65536);

let tinynet: Ipv4Network = "0.0.0.0/32".parse().unwrap();
assert_eq!(tinynet.size(), 1);

pub fn nth(self, n: u32) -> Option<Ipv4Addr>[src]

Returns the n:th address within this network. The adresses are indexed from 0 and n must be smaller than the size of the network.

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let net: Ipv4Network = "192.168.0.0/24".parse().unwrap();
assert_eq!(net.nth(0).unwrap(), Ipv4Addr::new(192, 168, 0, 0));
assert_eq!(net.nth(15).unwrap(), Ipv4Addr::new(192, 168, 0, 15));
assert!(net.nth(256).is_none());

let net2: Ipv4Network = "10.0.0.0/16".parse().unwrap();
assert_eq!(net2.nth(256).unwrap(), Ipv4Addr::new(10, 0, 1, 0));

Trait Implementations

impl Clone for Ipv4Network[src]

impl Copy for Ipv4Network[src]

impl Debug for Ipv4Network[src]

impl Display for Ipv4Network[src]

impl Eq for Ipv4Network[src]

impl From<Ipv4Addr> for Ipv4Network[src]

impl From<Ipv4Network> for IpNetwork[src]

impl FromStr for Ipv4Network[src]

Creates an Ipv4Network from parsing a string in CIDR notation.

Examples

use std::net::Ipv4Addr;
use ipnetwork::Ipv4Network;

let new = Ipv4Network::new(Ipv4Addr::new(10, 1, 9, 32), 16).unwrap();
let from_cidr: Ipv4Network = "10.1.9.32/16".parse().unwrap();
assert_eq!(new.ip(), from_cidr.ip());
assert_eq!(new.prefix(), from_cidr.prefix());

type Err = IpNetworkError

The associated error which can be returned from parsing.

impl Hash for Ipv4Network[src]

impl<'_> IntoIterator for &'_ Ipv4Network[src]

type IntoIter = Ipv4NetworkIterator

Which kind of iterator are we turning this into?

type Item = Ipv4Addr

The type of the elements being iterated over.

impl Ord for Ipv4Network[src]

impl PartialEq<Ipv4Network> for Ipv4Network[src]

impl PartialOrd<Ipv4Network> for Ipv4Network[src]

impl StructuralEq for Ipv4Network[src]

impl StructuralPartialEq for Ipv4Network[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CallHasher for T where
    T: Hash

impl<T> CallHasher for T where
    T: Hash + ?Sized

impl<T> Conv for T

impl<T> Conv for T

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,