Skip to main content

Crate auto_tuple

Crate auto_tuple 

Source
Expand description

Element-wise tuple-ization for traits.

#[auto_tuple] generates, for each requested arity, a helper trait whose methods/consts/types forward element-wise to each element of an N-tuple: (x, y).foo(a) desugars to (x.foo(a), y.foo(a)). See docs/design.md for the full semantics.

ⓘ
use auto_tuple::auto_tuple;

#[auto_tuple]
trait Tr {
    fn zero() -> usize;
}

struct X;
struct Y;

impl Tr for X { fn zero() -> usize { 1 } }
impl Tr for Y { fn zero() -> usize { 2 } }

use auto_tuple::_TrTuple2;   // helper trait must be in scope
assert_eq!(<(X, Y)>::zero(), (1, 2));

Attribute Macros§

auto_tuple
Generates tuple helper traits for the annotated trait.