Struct ipnetwork::Ipv4Network [−][src]
pub struct Ipv4Network { /* fields omitted */ }Represents a network range where the IP addresses are of v4
Methods
impl Ipv4Network[src]
impl Ipv4Networkpub fn new(addr: Ipv4Addr, prefix: u8) -> Result<Ipv4Network, IpNetworkError>[src]
pub fn new(addr: Ipv4Addr, prefix: u8) -> Result<Ipv4Network, IpNetworkError>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 iter(&self) -> Ipv4NetworkIterator[src]
pub fn iter(&self) -> Ipv4NetworkIteratorReturns 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 ip(&self) -> Ipv4Addrpub fn prefix(&self) -> u8[src]
pub fn prefix(&self) -> u8pub fn mask(&self) -> Ipv4Addr[src]
pub fn mask(&self) -> Ipv4AddrReturns 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/16".parse().unwrap(); assert_eq!(net.mask(), Ipv4Addr::new(255, 255, 0, 0));
pub fn network(&self) -> Ipv4Addr[src]
pub fn network(&self) -> Ipv4AddrReturns 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]
pub fn broadcast(&self) -> Ipv4AddrReturns 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]
pub fn contains(&self, ip: Ipv4Addr) -> boolChecks 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) -> u64[src]
pub fn size(&self) -> u64Returns 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]
pub fn nth(&self, n: u32) -> Option<Ipv4Addr>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 Debug for Ipv4Network[src]
impl Debug for Ipv4Networkfn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Clone for Ipv4Network[src]
impl Clone for Ipv4Networkfn clone(&self) -> Ipv4Network[src]
fn clone(&self) -> Ipv4NetworkReturns 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 Copy for Ipv4Network[src]
impl Copy for Ipv4Networkimpl Hash for Ipv4Network[src]
impl Hash for Ipv4Networkfn 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 PartialEq for Ipv4Network[src]
impl PartialEq for Ipv4Networkfn eq(&self, other: &Ipv4Network) -> bool[src]
fn eq(&self, other: &Ipv4Network) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Ipv4Network) -> bool[src]
fn ne(&self, other: &Ipv4Network) -> boolThis method tests for !=.
impl Eq for Ipv4Network[src]
impl Eq for Ipv4Networkimpl PartialOrd for Ipv4Network[src]
impl PartialOrd for Ipv4Networkfn partial_cmp(&self, other: &Ipv4Network) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Ipv4Network) -> Option<Ordering>This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Ipv4Network) -> bool[src]
fn lt(&self, other: &Ipv4Network) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Ipv4Network) -> bool[src]
fn le(&self, other: &Ipv4Network) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Ipv4Network) -> bool[src]
fn gt(&self, other: &Ipv4Network) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Ipv4Network) -> bool[src]
fn ge(&self, other: &Ipv4Network) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl Ord for Ipv4Network[src]
impl Ord for Ipv4Networkfn cmp(&self, other: &Ipv4Network) -> Ordering[src]
fn cmp(&self, other: &Ipv4Network) -> OrderingThis method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self1.21.0[src]
fn max(self, other: Self) -> SelfCompares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> SelfCompares and returns the minimum of two values. Read more
impl Display for Ipv4Network[src]
impl Display for Ipv4Networkfn fmt(&self, fmt: &mut Formatter) -> Result[src]
fn fmt(&self, fmt: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl FromStr for Ipv4Network[src]
impl FromStr for Ipv4NetworkCreates 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.
fn from_str(s: &str) -> Result<Ipv4Network, IpNetworkError>[src]
fn from_str(s: &str) -> Result<Ipv4Network, IpNetworkError>Parses a string s to return a value of this type. Read more
impl From<Ipv4Addr> for Ipv4Network[src]
impl From<Ipv4Addr> for Ipv4Networkfn from(a: Ipv4Addr) -> Ipv4Network[src]
fn from(a: Ipv4Addr) -> Ipv4NetworkPerforms the conversion.
impl From<Ipv4Network> for IpNetwork[src]
impl From<Ipv4Network> for IpNetworkfn from(v4: Ipv4Network) -> IpNetwork[src]
fn from(v4: Ipv4Network) -> IpNetworkPerforms the conversion.
Auto Trait Implementations
impl Send for Ipv4Network
impl Send for Ipv4Networkimpl Sync for Ipv4Network
impl Sync for Ipv4Network