Range

Trait Range 

Source
pub trait Range: Clone + Sized {
    type Address: Clone + Ord;

    // Required methods
    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;
}
Expand description

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.

Required Associated Types§

Required Methods§

Source

fn embiggen(&self) -> Option<Self>

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.
Source

fn host_address(&self) -> &Self::Address

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.

Source

fn prefix_length(&self) -> u8

Return the prefix length of the range.

§Example

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

Source

fn is_ipv6(&self) -> bool

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

Source

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

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§