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 the first ip.

Returns the last ip.

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

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

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

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

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

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

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

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

Performs the conversion.

Performs the conversion.

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)

recently added

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.