Trait libnetrangemerge::Range[][src]

pub trait Range: Clone + Sized {
    type Address: Clone + Ord;
    fn embiggen(&self) -> Option<Self>;
fn host_address(&self) -> &Self::Address;
fn prefix_length(&self) -> u8;
fn is_ipv6(&self) -> bool;
fn contains(&self, other: &Self) -> bool; }

Types that implements the Range trait represents a CIDR range.

Applications generally can use the built in types that implement Range in this library: IpRange, Ipv4Range, and Ipv6Range. However, those types are not available in no_std mode - in which case the application can implement its own type that implements this trait.

Associated Types

Loading content...

Required methods

fn embiggen(&self) -> Option<Self>[src]

Return the next larger range or None if there is no such valid range.

Examples

  1. 127.0.0.0/25 embiggens to Some(127.0.0.0/24).
  2. 127.0.1.0/24 embiggens to None.
  3. 0.0.0.0/0 embiggens to None.

fn host_address(&self) -> &Self::Address[src]

Return the host address for the range.

Example

If the range represents 127.0.0.0/24, this must return a reference to the address 127.0.0.0.

fn prefix_length(&self) -> u8[src]

Return the prefix length of the range.

Example

If the range represents 127.0.0.0/24, this must return the value 24.

fn is_ipv6(&self) -> bool[src]

Return true if this is an ipv6 range and false if it is an ipv4 range.

fn contains(&self, other: &Self) -> bool[src]

Return true if this range contains the other range and false otherwise.

Panic

This method may panic if self and other do not return the same value for is_ipv6.

Examples

  1. 127.0.0.0/24 contains 127.0.0.128/25.
  2. 127.0.0.128/25 does not contain 127.0.0.0/24.
  3. 127.0.0.0/24 contains 127.0.0.0/24.
  4. 0.0.0.0/0 contains any other ipv4 network.
  5. 127.0.0.1/32 contains only itself.
Loading content...

Implementors

impl Range for IpRange[src]

type Address = IpAddr

impl Range for Ipv4Range[src]

type Address = Ipv4Addr

impl Range for Ipv6Range[src]

type Address = Ipv6Addr

Loading content...