Struct iptrie::Ipv4Prefix

source ·
pub struct Ipv4Prefix { /* private fields */ }
Expand description

An Ipv4 prefix similar to Ipv4Net but with trailing bits guaranteed to equal 0

Implementations§

source§

impl Ipv4Prefix

source

pub fn new(addr: Ipv4Addr, len: u8) -> Result<Self, IpPrefixError>

Build a new prefix.

All the bits greater than the prefix length are set to `0``. If the specified length is greater than the maximum allowed, an error is returned.

Example
use std::net::{Ipv4Addr, Ipv6Addr};
    use ipnet::PrefixLenError;
    let ipv4 = "1.2.3.4".parse::<Ipv4Addr>().unwrap();
    let ipv6 = "1:2:3:4::".parse::<Ipv6Addr>().unwrap();

    assert!( Ipv4Prefix::new(ipv4, 12).is_ok());

    assert_eq!( Ipv4Prefix::new(ipv4, 64), Err(IpPrefixError::PrefixLenError));

Trait Implementations§

source§

impl Clone for Ipv4Prefix

source§

fn clone(&self) -> Ipv4Prefix

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 Ipv4Prefix

source§

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

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

impl Default for Ipv4Prefix

source§

fn default() -> Ipv4Prefix

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

impl Display for Ipv4Prefix

source§

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

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

impl From<Ipv4Addr> for Ipv4Prefix

source§

fn from(value: Ipv4Addr) -> Self

Converts to this type from the input type.
source§

impl From<Ipv4Net> for Ipv4Prefix

source§

fn from(value: Ipv4Net) -> Self

Converts to this type from the input type.
source§

impl From<Ipv4Prefix> for Ipv4Net

source§

fn from(value: Ipv4Prefix) -> Self

Converts to this type from the input type.
source§

impl FromStr for Ipv4Prefix

§

type Err = IpPrefixError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for Ipv4Prefix

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 IpPrefix for Ipv4Prefix

§

type Slot = u32

The slot manipulated inside this prefix
source§

fn root() -> Self

Root prefix has a length of 0
source§

fn bitslot(&self) -> Self::Slot

The inner slot as is Read more
source§

fn bitslot_trunc(&self) -> Self::Slot

The inner slot with all the masked bits set to 0. Read more
source§

fn len(&self) -> u8

Length of the prefix. Read more
source§

const MAX_LEN: u8 = 32u8

The maximum allowed length for this prefix
§

type Addr = Ipv4Addr

The underlying ip address (usually Ipv4Addr or Ipv6Addr)
source§

fn network(&self) -> Self::Addr

The address of the network defined by the prefixv Read more
source§

fn bitmask(&self) -> Self::Slot

Mask of the prefix. Read more
source§

impl IpPrefixCovering<Ipv4Addr> for Ipv4Prefix

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv4Net> for Ipv4Prefix

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl IpPrefixCovering<Ipv4Prefix> for Ipv4Net

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
source§

impl PartialEq<Ipv4Prefix> for Ipv4Prefix

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Ipv4Prefix

source§

impl Eq for Ipv4Prefix

source§

impl StructuralEq for Ipv4Prefix

source§

impl StructuralPartialEq for Ipv4Prefix

Auto Trait Implementations§

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<P> IpPrefixCovering<P> for Pwhere P: IpPrefix,

source§

fn covering(&self, other: &P) -> IpPrefixCoverage

source§

fn covers(&self, other: &P) -> bool

Checks the coverage of this prefix against a set of addresses Read more
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.