49 releases (12 breaking)

0.14.16 Nov 19, 2024
0.14.15 Jun 5, 2024
0.14.14 May 27, 2024
0.8.1 Mar 5, 2024

#202 in Data structures

Download history 1/week @ 2024-08-17 6/week @ 2024-08-24 7/week @ 2024-08-31 5/week @ 2024-09-14 30/week @ 2024-09-21 135/week @ 2024-09-28 2/week @ 2024-10-05 172/week @ 2024-11-16 33/week @ 2024-11-23 29/week @ 2024-11-30

234 downloads per month
Used in 3 crates

MIT/Apache

305KB
3K SLoC

tuplez

This crate introduces a tuple type represented in recursive form rather than parallel form.

Motivation

The primitive tuple types are represented in parallel form, like:

(a, b, c, d ...)

Since Rust doesn't support variadic generics, we cannot add methods to primitive tuples with any number of elements.

Currently, most tuple crates use declarative macros to implement methods for tuples whose number of elements is less than a certain limit (usually 32).

To solve this, tuplez introduces a Tuple type represented in recursive form, like:

Tuple(a, Tuple(b, Tuple(c, Tuple(d, ...))))

The advantage of this representation is that you can implement methods recursively for all tuples, and there is no longer a limit on the number of tuple's elements. And, in almost all cases, the Tuple takes no more memory than the primitive tuples.

Functionality

  • Create tuples with any number of elements.
  • Access elements in a tuple at any index, or by their types.
  • Push element to a tuple or pop element from a tuple.
  • Join two tuples or split a tuple into two parts.
  • Rich tuple operations, e.g.: reverse, left rotate, zip.
  • Get subsequences.
  • If all element types implement a Trait (e.g. Eq, Add), then the Tuple also implement that Trait.
  • Traverse all elements of a tuple, or fold a tuple.
  • When the number of elements of a tuple doesn't exceed 32, then it can be converted from/to a primitive tuple or a primitive array.

Please check the documentation for details.

Dependencies

~225–720KB
~17K SLoC