TupleLenEqTo

Trait TupleLenEqTo 

Source
pub trait TupleLenEqTo<T: TupleLike>: TupleLike { }
Expand description

A Marker trait to indicate that two tuple types have the same number of elements.

FIXME: Once the generic_const_exprs feature and the associated_const_equality feature are stabilized, this trait is no longer needed. Instead, we can write:

use tuplez::TupleLike;

fn use_tuple<T, U>(t: T, u: U)
where
    T: TupleLike,
    U: TupleLike<LEN = { T::LEN }>,
{
    // ...
}

§Example

Use with tuple_t! macro to constrain the number of elements of the tuple.

use tuplez::{tuple, tuple_t, TupleLenEqTo, TupleLike};

fn only_accept_5_elements<T>(_: T)
where
    T: TupleLenEqTo<tuple_t!((); 5)>
{
}

let tup4 = tuple!(1, 2.0, "3", 4);
// only_accept_5_elements(tup4);    // Error: the trait bound is not satisfied
let tup5 = tup4.push_back('5');
only_accept_5_elements(tup5);       // Ok
let tup6 = tup5.push_back(6.0);
// only_accept_5_elements(tup6);    // Error: the trait bound is not satisfied

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl TupleLenEqTo<Unit> for Unit

Source§

impl<First1, Other1, First2, Other2> TupleLenEqTo<Tuple<First2, Other2>> for Tuple<First1, Other1>
where Other1: TupleLenEqTo<Other2>, Other2: TupleLike,