Struct IpAddrV4

Source
pub struct IpAddrV4 { /* private fields */ }
Expand description

Implements IP version 4 style addresses.

Implementations§

Source§

impl IpAddrV4

Source

pub fn new(a: u8, b: u8, c: u8, d: u8) -> IpAddrV4

Returns a IP-v4 address.

The result will represent the IP address a.b.c.d.

§Examples
use asyncio::ip::IpAddrV4;

let ip = IpAddrV4::new(192,168,0,1);
Source

pub fn any() -> IpAddrV4

Returns a unspecified IP-v4 address.

§Examples
use asyncio::ip::IpAddrV4;

let ip = IpAddrV4::any();
assert_eq!(ip, IpAddrV4::new(0,0,0,0));
Source

pub fn loopback() -> IpAddrV4

Returns a IP-v4 address for a loopback address.

§Examples
use asyncio::ip::IpAddrV4;

let ip = IpAddrV4::loopback();
assert_eq!(ip, IpAddrV4::new(127,0,0,1));
Source

pub fn is_unspecified(&self) -> bool

Returns true for if this is a unspecified address 0.0.0.0.

§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::any().is_unspecified());
Source

pub fn is_loopback(&self) -> bool

Return true for if this is a loopback address 127.0.0.1.

§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::loopback().is_loopback());
Source

pub fn is_class_a(&self) -> bool

Returns true for if this is a class A address.

The class A address ranges:

  • 10.0.0.0/8
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(10,0,0,1).is_class_a());
Source

pub fn is_class_b(&self) -> bool

Returns true for if this is a class B address.

The class B address ranges:

  • 172.16.0.0/12
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(172,16,0,1).is_class_b());
Source

pub fn is_class_c(&self) -> bool

Returns true for if this is a class C address.

The class c address ranges:

  • 192.168.0.0/16
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(192,168,0,1).is_class_c());
Source

pub fn is_private(&self) -> bool

Returns true for if this is a private address.

The private address ranges:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(192,168,0,1).is_private());
Source

pub fn is_multicast(&self) -> bool

Returns true for if this is a class D address.

The class D address ranges:

  • 224.0.0.0/4
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(224,0,0,1).is_multicast());

Returns true for if this is a link-local address.

The link-local address ranges:

  • 169.254.0.0/16
§Examples
use asyncio::ip::IpAddrV4;

assert!(IpAddrV4::new(169,254,0,0).is_link_local());
Source

pub fn as_bytes(&self) -> &[u8; 4]

Returns 4 octets bytes.

§Examples
use asyncio::ip::IpAddrV4;

assert_eq!(IpAddrV4::new(169,254,0,1).as_bytes(), &[169,254,0,1]);
Source

pub fn to_u32(&self) -> u32

Returns u32 in host byte order.

§Examples
use asyncio::ip::IpAddrV4;

assert_eq!(IpAddrV4::new(10,0,0,1).to_u32(), 10*256*256*256+1);

Trait Implementations§

Source§

impl AddAssign<i64> for IpAddrV4

Source§

fn add_assign(&mut self, rhs: i64)

Performs the += operation. Read more
Source§

impl Clone for IpAddrV4

Source§

fn clone(&self) -> IpAddrV4

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 IpAddrV4

Source§

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

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

impl Default for IpAddrV4

Source§

fn default() -> IpAddrV4

Returns the “default value” for a type. Read more
Source§

impl Display for IpAddrV4

Source§

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

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

impl From<[u8; 4]> for IpAddrV4

Source§

fn from(bytes: [u8; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for IpAddrV4

Source§

fn from(addr: u32) -> Self

Converts to this type from the input type.
Source§

impl FromStr for IpAddrV4

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<IpAddrV4>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for IpAddrV4

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<'a, P: Protocol> IntoEndpoint<P> for &'a IpAddrV4

Source§

fn into_endpoint(self, port: u16) -> IpEndpoint<P>

Source§

impl<P: Protocol> IntoEndpoint<P> for IpAddrV4

Source§

fn into_endpoint(self, port: u16) -> IpEndpoint<P>

Source§

impl Ord for IpAddrV4

Source§

fn cmp(&self, other: &IpAddrV4) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for IpAddrV4

Source§

fn eq(&self, other: &IpAddrV4) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for IpAddrV4

Source§

fn partial_cmp(&self, other: &IpAddrV4) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl SubAssign<i64> for IpAddrV4

Source§

fn sub_assign(&mut self, rhs: i64)

Performs the -= operation. Read more
Source§

impl Eq for IpAddrV4

Source§

impl StructuralPartialEq for IpAddrV4

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.