Trait vectoreyes::array_utils::ArrayAdjacentPairs
source · [−]pub trait ArrayAdjacentPairs {
type T;
type AdjacentPairs;
fn pair_adjacent_maybe_odd(self, fallback: Self::T) -> Self::AdjacentPairs;
}
Required Associated Types
sourcetype AdjacentPairs
type AdjacentPairs
An array which is [Self::T; ceil(Self::LEN / 2)]
Required Methods
sourcefn pair_adjacent_maybe_odd(self, fallback: Self::T) -> Self::AdjacentPairs
fn pair_adjacent_maybe_odd(self, fallback: Self::T) -> Self::AdjacentPairs
Turn an array into an array of pairs where each element is paired with an adjacent element. If the array has odd length, use the fallback.
Example
use vectoreyes::array_utils::*;
assert_eq!(
[0, 1, 2, 3].pair_adjacent_maybe_odd(42),
[(0, 1), (2, 3)]
);
assert_eq!(
[0, 1, 2, 3, 4].pair_adjacent_maybe_odd(42),
[(0, 1), (2, 3), (4, 42)]
);