tuples
Type-level tuple utilities for building APIs that need compile-time reasoning over structure, ordering, and membership. The crate exposes a collection of zero-cost traits, helper types, and macros that let you navigate tuples as if they were type-level linked lists without paying a runtime penalty.
Features
- Structural traits such as
AsConsTuple,Has,HasOneOf,Iter,Pair, andSupersetfor expressing tuple invariants in public APIs. - Index navigation through the
Index,Here, andTheremarkers, making it possible to pluck elements based solely on their position. - Conversion helpers for projecting tuples into cons-style forms, allowing
recursive transformations and flattening via
flat::ToFlat. - A tiny
impl_tuple_trait!macro that fans out implementations across the supported tuple arities so you do not have to hand-write boilerplate. - Zero allocations and zero runtime state: everything is resolved via the type system and inlined trait impls.
Getting started
Add the crate to your Cargo.toml:
[]
= "0.1"
Example
use ;
Trait surface overview
traits::as_cons_tuple::AsConsTuple– convert tuples into right-nested cons lists (owned, shared, or mutable).traits::cons_tuple– utilities for working directly with cons tuples.traits::has::Has/HasOneOf– index-based and predicate-based element accessors.traits::flat::ToFlat– flatten nested tuples while preserving order.traits::iter– iterate over homogeneous tuples without heap allocation.traits::pair– ergonomic helpers for two-element tuples.traits::superset::Superset– express containment relationships between tuple subsets.
Status & limitations
- The provided macro currently fans out implementations for tuple arities
up to five elements. Extending to larger tuples just requires updating
impl_tuple_trait!insrc/macros.rs. - The crate depends only on the Rust standard library. There are no runtime
allocations, but
std::marker::PhantomDatais used for index markers.
Development
All public modules and traits are documented, and CI will fail on missing
docs thanks to #![deny(missing_docs)] in lib.rs.