Struct net_adds::Ipv4AddrRange [−][src]
pub struct Ipv4AddrRange { /* fields omitted */ }
Expand description
An IPv4 address range.
See crate::IpAddrRange
for a type encompassing both IPv4 and IPv6 range.
The size of an Ipv4AddrRange
struct may vary depending on the target operating
system.
Textual representation
Ipv4AddrRange
provides a FromStr
implementation.
The two parts are represented by Ipv4Addr and are separated by ‘-’.
Examples
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let a = Ipv4Addr::new(192, 168, 0, 0); let b = Ipv4Addr::new(192, 168, 0, 255); let range = Ipv4AddrRange::new(a, b); assert_eq!(Ok(range), "192.168.0.0-192.168.0.255".parse());
Implementations
Returns an Ipv4AddrRange
.
Returns all ips included in the range.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let a = Ipv4Addr::new(0, 0, 0, 0); let b = Ipv4Addr::new(0, 0, 0, 1); let c = Ipv4Addr::new(0, 0, 0, 2); assert_eq!(Ipv4AddrRange::new(a, c).all(), vec![a, b, c]); assert_eq!(Ipv4AddrRange::new(c, a).all(), vec![c, b, a]); assert_eq!(Ipv4AddrRange::new(a, a).all(), vec![a]);
Returns the number of ip’s included in the range.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let a = Ipv4Addr::new(192, 168, 0, 0); let b = Ipv4Addr::new(192, 168, 0, 10); let range = Ipv4AddrRange::new(a, b); assert_eq!(range.size(), 11); let range = Ipv4AddrRange::new(b, a); assert_eq!(range.size(), 11);
Returns true if the ip argument is included in the range, else returns false.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let a = Ipv4Addr::new(192, 168, 0, 0); let b = Ipv4Addr::new(192, 168, 0, 255); let range = Ipv4AddrRange::new(a, b); assert!(range.has(Ipv4Addr::new(192, 168, 0, 0))); assert!(range.has(Ipv4Addr::new(192, 168, 0, 142))); assert!(range.has(Ipv4Addr::new(192, 168, 0, 255))); assert!(!range.has(Ipv4Addr::new(192, 169, 0, 0))); let range = Ipv4AddrRange::new(b, a); assert!(range.has(Ipv4Addr::new(192, 168, 0, 0))); assert!(range.has(Ipv4Addr::new(192, 168, 0, 142))); assert!(range.has(Ipv4Addr::new(192, 168, 0, 255))); assert!(!range.has(Ipv4Addr::new(192, 169, 0, 0)));
Trait Implementations
Create an Ipv4AddrRange
from a tuple of two Ipv4Addr
.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let start = Ipv4Addr::new(0, 0, 0, 0); let end = Ipv4Addr::new(0, 0, 0, 10); assert_eq!(Ipv4AddrRange::from((start, end)), Ipv4AddrRange::new(start, end));
Create an IpAddrRange::V4
from an Ipv4AddrRange
.
Examples:
use std::net::Ipv4Addr; use net_adds::{IpAddrRange, Ipv4AddrRange}; let a = Ipv4Addr::new(0, 0, 0, 0); let b = Ipv4Addr::new(0, 0, 0, 10); assert_eq!(IpAddrRange::from(Ipv4AddrRange::new(a, b)), IpAddrRange::V4(Ipv4AddrRange::new(a, b)));
Parse a string as Ipv4AddrRange
.
If the string representation is not valid return an NetAddsError::RangeAddrParse(RangeAddrParseError)
.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let range = Ipv4AddrRange::new(Ipv4Addr::new(192, 168, 0, 0), Ipv4Addr::new(192, 168, 0, 255)); assert_eq!("192.168.0.0-192.168.0.255".parse(), Ok(range));
type Err = NetAddsError
type Err = NetAddsError
The associated error which can be returned from parsing.
Create a Ipv4Addr
iterator.
Examples:
use std::net::Ipv4Addr; use net_adds::Ipv4AddrRange; let mut iter = Ipv4AddrRange::new(Ipv4Addr::new(0, 0, 0, 0), Ipv4Addr::new(0, 0, 0, 2)).into_iter(); assert_eq!(iter.next(), Some(Ipv4Addr::from(0))); assert_eq!(iter.next(), Some(Ipv4Addr::from(1))); assert_eq!(iter.next(), Some(Ipv4Addr::from(2))); assert_eq!(iter.next(), None);
Create a smart Ipv4Addr
iterator.
Examples:
use std::net::Ipv4Addr; use net_adds::{Ipv4AddrRange, IntoSmartIterator}; let mut iter = Ipv4AddrRange::new(Ipv4Addr::new(0, 0, 0, 0), Ipv4Addr::new(0, 0, 0, 2)).into_smart_iter(); assert_eq!(iter.next(), Some(Ipv4Addr::from(0))); assert_eq!(iter.next(), Some(Ipv4Addr::from(1))); assert_eq!(iter.next(), Some(Ipv4Addr::from(2))); assert_eq!(iter.next(), None);
Which kind of iterator are we turning this into?
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
Auto Trait Implementations
impl RefUnwindSafe for Ipv4AddrRange
impl Send for Ipv4AddrRange
impl Sync for Ipv4AddrRange
impl Unpin for Ipv4AddrRange
impl UnwindSafe for Ipv4AddrRange
Blanket Implementations
Mutably borrows from an owned value. Read more