Crate tuple_traits

Source
Expand description

tuple-traits

Additional traits to enable some cursed ergonomic types.

crates.io docs.rs checks

§Traits

§Append

Append a type to a tuple.

static_assertions::assert_type_eq_all!(
    <(usize, char) as tuple_traits::Append>::Append<bool>,
    (usize, char, bool)
);

§Cons

Represent a tuple as a cons (ish) value, with the first value on the left, and the rest of the tuple on the right.

static_assertions::assert_impl_all!(
    (usize, usize, usize): tuple_traits::Cons<Left = usize, Right = (usize, usize)>
);

§Contains

A trait that will only be implement for a given target if it is present within a given type.

struct A;
struct B;
struct C;

fn requires_c<T, Index>(value: T)
where
    T: tuple_traits::Contains<C, Index>
{
}

// Works!
requires_c((A, B, C));

// Compiler error: `C` does not appear within `(A, B)`
// requires_c((A, B));

§Example

Check out ./examples/buffer-flags.rs for a full example!

Structs§

There
Index value to indicate that the target is at some other index of a Cons.

Enums§

Here
Index value to indicate the target is in the left of a Cons.

Traits§

Append
Trait to append some value to the end of a tuple.
Cons
A base type that can be implemented by any type, which is used to build operations on top of. With this format it can be implemented to an infinite length, meaning that any operations built from it will work for any given length.
Contains
Determine whether a target is located at some index. This trait will be implemented for all types that contain the target type.