Trait vector2math::Pair

source ·
pub trait Pair: Sized {
    type Item;

    // Required methods
    fn into_pair(self) -> (Self::Item, Self::Item);
    fn from_items(a: Self::Item, b: Self::Item) -> Self;
    fn first(&self) -> Self::Item;
    fn second(&self) -> Self::Item;

    // Provided methods
    fn pairwise<O, P, F, R>(self, other: O, f: F) -> P
       where O: Pair,
             P: Pair<Item = R>,
             F: Fn(Self::Item, O::Item) -> R { ... }
    fn pair_iter(self) -> Chain2<Self::Item> { ... }
}
Expand description

Trait for defining a pair of items of the same type.

This trait is meant to generalize having two similar things. It is implemented for (T, T) and [T; 2] with Item = T. However, because a pair does not necessarily have to be an actual pair It is also implemented for (T, T, T, T) and [T; 4] with Item = (T, T) and Item = [T; 2] respectively.

Required Associated Types§

source

type Item

The type of the pair’s item

Required Methods§

source

fn into_pair(self) -> (Self::Item, Self::Item)

Get the pair

source

fn from_items(a: Self::Item, b: Self::Item) -> Self

Create a pair from two items

source

fn first(&self) -> Self::Item

Get the first item

source

fn second(&self) -> Self::Item

Get the second item

Provided Methods§

source

fn pairwise<O, P, F, R>(self, other: O, f: F) -> Pwhere O: Pair, P: Pair<Item = R>, F: Fn(Self::Item, O::Item) -> R,

Apply a function pairwise to the items of two pairs

source

fn pair_iter(self) -> Chain2<Self::Item>

Get an iterator over the pair’s items

Implementations on Foreign Types§

source§

impl<T> Pair for [T; 4]where T: Copy,

§

type Item = [T; 2]

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

source§

impl<T> Pair for [T; 2]where T: Copy,

§

type Item = T

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

source§

impl<T> Pair for (T, T, T, T, T, T)where T: Clone,

§

type Item = (T, T, T)

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

source§

impl<T> Pair for [T; 6]where T: Copy,

§

type Item = [T; 3]

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

source§

impl<T> Pair for (T, T)where T: Clone,

§

type Item = T

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

source§

impl<T> Pair for (T, T, T, T)where T: Clone,

§

type Item = (T, T)

source§

fn into_pair(self) -> (Self::Item, Self::Item)

source§

fn from_items(a: Self::Item, b: Self::Item) -> Self

source§

fn first(&self) -> Self::Item

source§

fn second(&self) -> Self::Item

Implementors§