typed_tuple
Typed Tuple
Type based operations on primitive tuple elements.
Functionality
typed_tuple allows for type safe operations on primitive tuple elements
without specifying an index. The main purpose of this crate is to simplfy
small arbitrary operations on heterogenous sequences. In the example below,
elements of a tuple are assigned and retrieved irrespective of indices:
let mut tuple: = Defaultdefault;
// Mutate the `usize` element.
tuple.map;;
// Assign the `Type` prefixed elements.
*tuple.get_mut = Some;
*tuple.get_mut = Some;
// Pass elements to their respective consumers.
if let Some = tuple.get
if let Some = tuple.get
if let Some = tuple.get
assert_eq!;
Limitations
- Fields of the same type must still specify a constant index. This can be specified
with, for example,
TypedTuple::<1, _>::get(&tuple)where1is the element index, however this offers no advantage over simply callingtuple.1. typed_tuplecan impact readability. Types should be explicit if not immediately obvious. Preferlet a: usize = tuple.get()overlet a = tuple.get().TypedTupleis implemented on tuples of up to 12 elements in length. This was chosen as it is the limit of many tuple trait implementations (PartialEq,Eq, etc.), however can be extended to support a higher number of elements if needed.
License: MIT OR Apache-2.0