Trait tuplez::ToArray

source ·
pub trait ToArray<T>: TupleLike {
    type Array: IntoIterator<Item = T>;
    type Iter<'a>: Iterator<Item = &'a T>
       where Self::AsRefOutput<'a>: ToArray<&'a T>,
             Self: 'a,
             T: 'a;
    type IterMut<'a>: Iterator<Item = &'a mut T>
       where Self::AsMutOutput<'a>: ToArray<&'a mut T>,
             Self: 'a,
             T: 'a;

    // Required methods
    fn to_array(self) -> Self::Array;
    fn iter<'a>(&'a self) -> Self::Iter<'a>
       where Self::AsRefOutput<'a>: ToArray<&'a T>,
             Self: 'a,
             T: 'a;
    fn iter_mut<'a>(&'a mut self) -> Self::IterMut<'a>
       where Self::AsMutOutput<'a>: ToArray<&'a mut T>,
             Self: 'a,
             T: 'a;
}
Expand description

Convert from tuples to primitive arrays, if all elements of the tuple are of the same type.

Because the generic constant expressions feature is still unstable yet, we can only limit the maximum number of elements of the tuple that implement ToArray to 32, just like what we did with the primitive tuples.

However, if you are OK with using rustc released to nightly channel to compile codes with unstable features, you can enable the any_array feature to implement ToArray on tuples with no limit on the number of elements.

tuplez = { features = [ "any_array" ] }

Always remember: unstable features are not guaranteed by Rust and may not be available someday in the future.

Why <T> instead of type Item? Well, this is because the Units can be converted to any [T; 0].

Required Associated Types§

source

type Array: IntoIterator<Item = T>

The primitive array type to generate.

source

type Iter<'a>: Iterator<Item = &'a T> where Self::AsRefOutput<'a>: ToArray<&'a T>, Self: 'a, T: 'a

Immutable element iterator type.

source

type IterMut<'a>: Iterator<Item = &'a mut T> where Self::AsMutOutput<'a>: ToArray<&'a mut T>, Self: 'a, T: 'a

Mutable element iterator type.

Required Methods§

source

fn to_array(self) -> Self::Array

Convert from the tuple to the primitive array.

§Example
use tuplez::{tuple, ToArray};

let tup = tuple!(1, 2, 3, 4, 5, 6);
assert_eq!(tup.to_array(), [1, 2, 3, 4, 5, 6]);
source

fn iter<'a>(&'a self) -> Self::Iter<'a>
where Self::AsRefOutput<'a>: ToArray<&'a T>, Self: 'a, T: 'a,

Get immutable element iterator.

§Example
use tuplez::{tuple, ToArray};

let tup = tuple!(1, 2, 3, 4, 5, 6);
assert_eq!(tup.iter().sum::<i32>(), 21);
source

fn iter_mut<'a>(&'a mut self) -> Self::IterMut<'a>
where Self::AsMutOutput<'a>: ToArray<&'a mut T>, Self: 'a, T: 'a,

Get mutable element iterator.

§Example
use tuplez::{tuple, ToArray};

let mut tup = tuple!(1, 2, 3, 4, 5, 6);
tup.iter_mut().for_each(|v| *v += 1);
assert_eq!(tup.iter().sum::<i32>(), 27);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 32]

§

type Iter<'a> = IntoIter<&'a T, 32> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 32> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 31]

§

type Iter<'a> = IntoIter<&'a T, 31> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 31> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 30]

§

type Iter<'a> = IntoIter<&'a T, 30> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 30> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 29]

§

type Iter<'a> = IntoIter<&'a T, 29> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 29> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 28]

§

type Iter<'a> = IntoIter<&'a T, 28> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 28> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 27]

§

type Iter<'a> = IntoIter<&'a T, 27> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 27> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 26]

§

type Iter<'a> = IntoIter<&'a T, 26> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 26> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 25]

§

type Iter<'a> = IntoIter<&'a T, 25> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 25> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 24]

§

type Iter<'a> = IntoIter<&'a T, 24> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 24> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 23]

§

type Iter<'a> = IntoIter<&'a T, 23> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 23> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 22]

§

type Iter<'a> = IntoIter<&'a T, 22> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 22> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 21]

§

type Iter<'a> = IntoIter<&'a T, 21> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 21> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 20]

§

type Iter<'a> = IntoIter<&'a T, 20> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 20> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>>

§

type Array = [T; 19]

§

type Iter<'a> = IntoIter<&'a T, 19> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 19> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>>

§

type Array = [T; 18]

§

type Iter<'a> = IntoIter<&'a T, 18> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 18> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>>

§

type Array = [T; 17]

§

type Iter<'a> = IntoIter<&'a T, 17> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 17> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>>

§

type Array = [T; 16]

§

type Iter<'a> = IntoIter<&'a T, 16> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 16> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>>

§

type Array = [T; 15]

§

type Iter<'a> = IntoIter<&'a T, 15> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 15> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>>

§

type Array = [T; 14]

§

type Iter<'a> = IntoIter<&'a T, 14> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 14> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>>

§

type Array = [T; 13]

§

type Iter<'a> = IntoIter<&'a T, 13> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 13> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>>

§

type Array = [T; 12]

§

type Iter<'a> = IntoIter<&'a T, 12> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 12> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>>

§

type Array = [T; 11]

§

type Iter<'a> = IntoIter<&'a T, 11> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 11> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>>

§

type Array = [T; 10]

§

type Iter<'a> = IntoIter<&'a T, 10> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 10> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>>

§

type Array = [T; 9]

§

type Iter<'a> = IntoIter<&'a T, 9> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 9> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>>

§

type Array = [T; 8]

§

type Iter<'a> = IntoIter<&'a T, 8> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 8> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>>

§

type Array = [T; 7]

§

type Iter<'a> = IntoIter<&'a T, 7> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 7> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>>

§

type Array = [T; 6]

§

type Iter<'a> = IntoIter<&'a T, 6> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 6> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>>

§

type Array = [T; 5]

§

type Iter<'a> = IntoIter<&'a T, 5> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 5> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Tuple<T, Unit>>>>

§

type Array = [T; 4]

§

type Iter<'a> = IntoIter<&'a T, 4> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 4> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Tuple<T, Unit>>>

§

type Array = [T; 3]

§

type Iter<'a> = IntoIter<&'a T, 3> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 3> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Tuple<T, Unit>>

§

type Array = [T; 2]

§

type Iter<'a> = IntoIter<&'a T, 2> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 2> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Tuple<T, Unit>

§

type Array = [T; 1]

§

type Iter<'a> = IntoIter<&'a T, 1> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 1> where Self: 'a, T: 'a

source§

impl<T> ToArray<T> for Unit

§

type Array = [T; 0]

§

type Iter<'a> = IntoIter<&'a T, 0> where Self: 'a, T: 'a

§

type IterMut<'a> = IntoIter<&'a mut T, 0> where Self: 'a, T: 'a