pub enum MaybePec<T> {
Single(T),
Pec(Ipv4Net, Vec<T>),
}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>
impl<T> MaybePec<T>
Sourcepub fn first(&self) -> &T
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.
Sourcepub fn to_vec(self) -> Vec<T>
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.
Sourcepub fn unwrap_single(self) -> T
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.
Sourcepub fn single_or(self) -> Result<T, ExportError>
pub fn single_or(self) -> Result<T, ExportError>
Get the single value, or return ExportError::UnexpectedPec.
Sourcepub fn single_or_err<E>(self, err: E) -> Result<T, E>
pub fn single_or_err<E>(self, err: E) -> Result<T, E>
Get the single value, or return Err(err).
Sourcepub fn single_or_else<E, F: FnOnce(Vec<T>) -> E>(self, err: F) -> Result<T, E>
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.
Sourcepub fn map<R, F: FnMut(T) -> R>(self, f: F) -> MaybePec<R>
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.
Sourcepub fn iter(&self) -> MaybePecIter<'_, T> ⓘ
pub fn iter(&self) -> MaybePecIter<'_, T> ⓘ
Iterate over all values stored in self as references.
Sourcepub fn sample_random_n<R: Rng>(&self, rng: &mut R, n: usize) -> Vec<&T>where
T: Ord,
Available on crate feature rand only.
pub fn sample_random_n<R: Rng>(&self, rng: &mut R, n: usize) -> Vec<&T>where
T: Ord,
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.
Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a MaybePec<T>
impl<'a, T> IntoIterator for &'a MaybePec<T>
Source§impl<T> IntoIterator for MaybePec<T>
impl<T> IntoIterator for MaybePec<T>
impl<T: Eq> Eq for MaybePec<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<'n, P, Q, Ospf, I, K, V> NetworkFormatterMap<'n, P, Q, Ospf> for Iwhere
P: Prefix,
Ospf: OspfImpl,
I: IntoIterator<Item = (K, V)>,
K: NetworkFormatter<'n, P, Q, Ospf>,
V: NetworkFormatter<'n, P, Q, Ospf>,
impl<'n, P, Q, Ospf, I, K, V> NetworkFormatterMap<'n, P, Q, Ospf> for Iwhere
P: Prefix,
Ospf: OspfImpl,
I: IntoIterator<Item = (K, V)>,
K: NetworkFormatter<'n, P, Q, Ospf>,
V: NetworkFormatter<'n, P, Q, Ospf>,
Source§impl<'n, P, Q, Ospf, I, T> NetworkFormatterNestedSequence<'n, P, Q, Ospf> for Iwhere
P: Prefix,
Ospf: OspfImpl,
I: IntoIterator<Item = T>,
T: NetworkFormatterSequence<'n, P, Q, Ospf>,
impl<'n, P, Q, Ospf, I, T> NetworkFormatterNestedSequence<'n, P, Q, Ospf> for Iwhere
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
fn fmt_path_options(self, net: &'n Network<P, Q, Ospf>) -> String
a -> b -> c | a -> cSource§fn fmt_path_set(self, net: &'n Network<P, Q, Ospf>) -> String
fn fmt_path_set(self, net: &'n Network<P, Q, Ospf>) -> String
{a -> b -> c, a -> c}Source§impl<'n, P, Q, Ospf, I, T> NetworkFormatterSequence<'n, P, Q, Ospf> for I
impl<'n, P, Q, Ospf, I, T> NetworkFormatterSequence<'n, P, Q, Ospf> for I
Source§fn fmt_set(self, net: &'n Network<P, Q, Ospf>) -> String
fn fmt_set(self, net: &'n Network<P, Q, Ospf>) -> String
{a, b, c}.Source§fn fmt_set_multiline(
self,
net: &'n Network<P, Q, Ospf>,
indent: usize,
) -> String
fn fmt_set_multiline( self, net: &'n Network<P, Q, Ospf>, indent: usize, ) -> String
Source§fn fmt_list(self, net: &'n Network<P, Q, Ospf>) -> String
fn fmt_list(self, net: &'n Network<P, Q, Ospf>) -> String
[a, b, c].