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§
Sourcefn host_address(&self) -> &Self::Address
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.
Sourcefn prefix_length(&self) -> u8
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.
Sourcefn is_ipv6(&self) -> bool
fn is_ipv6(&self) -> bool
Return true if this is an ipv6 range and false if
it is an ipv4 range.
Sourcefn contains(&self, other: &Self) -> bool
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
127.0.0.0/24contains127.0.0.128/25.127.0.0.128/25does not contain127.0.0.0/24.127.0.0.0/24contains127.0.0.0/24.0.0.0.0/0contains any other ipv4 network.127.0.0.1/32contains 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.