MaybePec

Enum MaybePec 

Source
pub enum MaybePec<T> {
    Single(T),
    Pec(Ipv4Net, Vec<T>),
}
Available on crate feature export only.
Expand description

A datastructure that contains a single value if it corresponds to a single network, or a vector ov values if it corresponds to a prefix equivalence class.

Variants§

§

Single(T)

A single value

§

Pec(Ipv4Net, Vec<T>)

A vector of alues that correspond to a previx equivalence class

Implementations§

Source§

impl<T> MaybePec<T>

Source

pub fn first(&self) -> &T

Get the first element in the structure. For Self::Single, this simply returns a reference to the value. For Self::Pec, this returns the reference to the first value. This function panics if the PEC was registered without any associated prefix.

Source

pub fn to_vec(self) -> Vec<T>

Get a vector containing all elements. If self is a single value, then this function returns a vector containing a single value. Otherwise, it will return a vector containing multiple values.

Source

pub fn unwrap_single(self) -> T

Expect that the prefix is a single value, and return it. If the prefix belongs to a prefix equivalence class, this function panics.

Source

pub fn single(self) -> Option<T>

Get the single value or None.

Source

pub fn single_or(self) -> Result<T, ExportError>

Get the single value, or return ExportError::UnexpectedPec.

Source

pub fn single_or_err<E>(self, err: E) -> Result<T, E>

Get the single value, or return Err(err).

Source

pub fn single_or_else<E, F: FnOnce(Vec<T>) -> E>(self, err: F) -> Result<T, E>

Get the single value, or return Error(err(v)), where v is the vector of elements contained within self.

Source

pub fn map<R, F: FnMut(T) -> R>(self, f: F) -> MaybePec<R>

Apply a function to every element, returning a MaybePec with the mapped values.

Source

pub fn iter(&self) -> MaybePecIter<'_, T>

Iterate over all values stored in self as references.

Source

pub fn sample_random_n<R: Rng>(&self, rng: &mut R, n: usize) -> Vec<&T>
where T: Ord,

Available on crate feature rand only.

Get random samples from the prefix equivalence class. If n is smaller or equal to the size of the equivalence class, then simply return all elements. Otherwise, return the first, the last, and some random elements in between.

Source

pub fn sample_uniform_n(&self, n: usize) -> Vec<&T>
where T: Ord,

Get n samples from the prefix equivalence class that are equally spaced. This function may panic if n < 2. If n == 2, then return the smallest and largest element.

Trait Implementations§

Source§

impl<T: Clone> Clone for MaybePec<T>

Source§

fn clone(&self) -> MaybePec<T>

Returns a duplicate 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<T: Debug> Debug for MaybePec<T>

Source§

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

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

impl<T: Display> Display for MaybePec<T>

Source§

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

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

impl<T: Hash> Hash for MaybePec<T>

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, T> IntoIterator for &'a MaybePec<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = MaybePecIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for MaybePec<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for MaybePec<T>

Source§

fn eq(&self, other: &MaybePec<T>) -> 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<T: Eq> Eq for MaybePec<T>

Source§

impl<T> StructuralPartialEq for MaybePec<T>

Auto Trait Implementations§

§

impl<T> Freeze for MaybePec<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MaybePec<T>
where T: RefUnwindSafe,

§

impl<T> Send for MaybePec<T>
where T: Send,

§

impl<T> Sync for MaybePec<T>
where T: Sync,

§

impl<T> Unpin for MaybePec<T>
where T: Unpin,

§

impl<T> UnwindSafe for MaybePec<T>
where T: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'n, P, Q, Ospf, I, K, V> NetworkFormatterMap<'n, P, Q, Ospf> for I
where P: Prefix, Ospf: OspfImpl, I: IntoIterator<Item = (K, V)>, K: NetworkFormatter<'n, P, Q, Ospf>, V: NetworkFormatter<'n, P, Q, Ospf>,

Source§

fn fmt_map(self, net: &'n Network<P, Q, Ospf>) -> String

Format the map on a single line, e.g., {a: 1, b: 2}
Source§

fn fmt_map_multiline( self, net: &'n Network<P, Q, Ospf>, indent: usize, ) -> String

Format the iterator as a list, e.g., [a, b, c].
Source§

impl<'n, P, Q, Ospf, I, T> NetworkFormatterNestedSequence<'n, P, Q, Ospf> for I
where P: Prefix, Ospf: OspfImpl, I: IntoIterator<Item = T>, T: NetworkFormatterSequence<'n, P, Q, Ospf>,

Source§

fn fmt_path_options(self, net: &'n Network<P, Q, Ospf>) -> String

Format path options on a single line, e.g., a -> b -> c | a -> c
Source§

fn fmt_path_set(self, net: &'n Network<P, Q, Ospf>) -> String

Format path options as a set on a single line, e.g., {a -> b -> c, a -> c}
Source§

fn fmt_path_multiline( self, net: &'n Network<P, Q, Ospf>, indent: usize, ) -> String

Format path options as a seton multiple lines.
Source§

impl<'n, P, Q, Ospf, I, T> NetworkFormatterSequence<'n, P, Q, Ospf> for I
where P: Prefix, Ospf: OspfImpl, I: IntoIterator<Item = T>, T: NetworkFormatter<'n, P, Q, Ospf>,

Source§

fn fmt_set(self, net: &'n Network<P, Q, Ospf>) -> String

Format the iterator as a set, e.g., {a, b, c}.
Source§

fn fmt_set_multiline( self, net: &'n Network<P, Q, Ospf>, indent: usize, ) -> String

Format the iterator as a set over multiple lines.
Source§

fn fmt_list(self, net: &'n Network<P, Q, Ospf>) -> String

Format the iterator as a list, e.g., [a, b, c].
Source§

fn fmt_list_multiline( self, net: &'n Network<P, Q, Ospf>, indent: usize, ) -> String

Format the iterator as a milti-line list.
Source§

fn fmt_path(self, net: &'n Network<P, Q, Ospf>) -> String

Format the iterator as a path, e.g., a -> b -> c.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<'a, P, I> RouteMapList<P> for I
where P: Prefix + 'a, I: IntoIterator<Item = &'a RouteMap<P>>,

Source§

fn apply(self, entry: BgpRibEntry<P>) -> Option<BgpRibEntry<P>>

Apply the route to the sequence of route-maps. This sequence must be sorted by the route-map order.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V