Struct subnetwork::Ipv4

source ·
pub struct Ipv4 { /* private fields */ }

Implementations§

source§

impl Ipv4

source

pub fn new(address: Ipv4Addr) -> Result<Ipv4, AddrParseError>

Constructs a new Ipv4 from a given Ipv4Addr.

source

pub fn from(address: &str) -> Result<Ipv4, AddrParseError>

Constructs a new Ipv4 from a given &str.

source

pub fn iter(&self, netmask: usize) -> Ipv4Pool

Returns an Ipv4 iterator over the addresses contained in the network.

Example
use subnetwork::Ipv4;

fn main() {
    let ipv4 = Ipv4::from("192.168.1.1").unwrap();
    for i in ipv4.iter(24) {
        println!("{:?}", i);
    }
}
source

pub fn within_from_str( &self, subnet_address: &str ) -> Result<bool, InvalidInputError>

Check if the ip is within a subnet.

Example
use subnetwork::Ipv4;

fn main() {
    let ipv4 = Ipv4::from("192.168.1.1").unwrap();
    let ret = ipv4.within_from_str("192.168.1.0/24").unwrap();
    assert_eq!(ret, true);
}
source

pub fn within(&self, subnet_address: Ipv4Pool) -> bool

Check if the ip is within a subnet.

Example
use subnetwork::{Ipv4, Ipv4Pool};

fn main() {
    let ipv4 = Ipv4::from("192.168.1.1").unwrap();
    let ipv4_pool = Ipv4Pool::from("192.168.1.0/24").unwrap();
    let ret = ipv4.within(ipv4_pool);
    assert_eq!(ret, true);
}
source

pub fn network(&self, netmask: usize) -> Ipv4Addr

Returns the address of the network denoted by this Ipv4. This means the lowest possible IP address inside of the network.

source

pub fn broadcast(&self, netmask: usize) -> Ipv4Addr

Returns the broadcasting address of this Ipv4. This means the highest possible IP address inside of the network.

source

pub fn size(&self, netmask: usize) -> usize

Returns the number of possible host addresses in this Ipv4 (include 0 and 255)

source

pub fn len(&self, netmask: usize) -> usize

Returns the number of valid addresses in this Ipv4 (NOT include 0 and 255)

source

pub fn to_std(&self) -> Ipv4Addr

Returns the standard IPv4 address.

Trait Implementations§

source§

impl Clone for Ipv4

source§

fn clone(&self) -> Ipv4

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ipv4

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Ipv4

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for Ipv4

Auto Trait Implementations§

§

impl RefUnwindSafe for Ipv4

§

impl Send for Ipv4

§

impl Sync for Ipv4

§

impl Unpin for Ipv4

§

impl UnwindSafe for Ipv4

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.