Expand description
Rust tuple extension.
§Features
-
adding/removing element at front/back
-
converting heterogeneous tuples to homogeneous ones
-
checking the length bound of the given tuple in
where
clause
§Examples: list operations
use tuplex::*;
let tuple = ();
assert_eq!( tuple.len(), 0 );
let tuple = tuple.push_front( 0 );
assert_eq!( tuple, (0,) );
assert_eq!( tuple.len(), 1 );
let tuple = tuple.push_front( false );
assert_eq!( tuple, (false,0) );
assert_eq!( tuple.len(), 2 );
let tuple = tuple.push_back( true );
assert_eq!( tuple, (false,0,true) );
assert_eq!( tuple.len(), 3 );
let tuple = tuple.push_back( 1 );
assert_eq!( tuple, (false,0,true,1) );
assert_eq!( tuple.len(), 4 );
let (front,tuple) = tuple.pop_front();
assert_eq!( front, false );
assert_eq!( tuple, (0,true,1) );
let (back,tuple) = tuple.pop_back();
assert_eq!( back, 1 );
assert_eq!( tuple, (0,true) );
§Examples: homogeneous/heterogeneous conversions
use tuplex::*;
// `into_homo_tuple()` works because i32 can be converted from i3, u16 and i32.
assert_eq!( (3_i8, 7_u16, 21_i32).into_homo_tuple(), (3_i32, 7_i32, 21_i32) );
§Examples: Length bound
- checking the length bound of the given tuple in
where
clause
use tuplex::*;
fn foo<Val,Tag>( val: Val ) where Val: LenExceeds<[();3],Tag> {}
foo((0,0,0,0));
// foo((0,0,0)); // won't compile
Macros§
- homo_
tuple - Denotes a tuple type, the fields of which are of the same type. Up to 32 fields.
Structs§
- HTup0
- HTup1
- HTup2
- HTup3
- HTup4
- HTup5
- HTup6
- HTup7
- HTup8
- HTup9
- HTup10
- HTup11
- HTup12
- HTup13
- HTup14
- HTup15
- HTup16
- HTup17
- HTup18
- HTup19
- HTup20
- HTup21
- HTup22
- HTup23
- HTup24
- HTup25
- HTup26
- HTup27
- HTup28
- HTup29
- HTup30
- HTup31
- HTup32
- HTup
Iter0 - HTup
Iter1 - HTup
Iter2 - HTup
Iter3 - HTup
Iter4 - HTup
Iter5 - HTup
Iter6 - HTup
Iter7 - HTup
Iter8 - HTup
Iter9 - HTup
Iter10 - HTup
Iter11 - HTup
Iter12 - HTup
Iter13 - HTup
Iter14 - HTup
Iter15 - HTup
Iter16 - HTup
Iter17 - HTup
Iter18 - HTup
Iter19 - HTup
Iter20 - HTup
Iter21 - HTup
Iter22 - HTup
Iter23 - HTup
Iter24 - HTup
Iter25 - HTup
Iter26 - HTup
Iter27 - HTup
Iter28 - HTup
Iter29 - HTup
Iter30 - HTup
Iter31 - HTup
Iter32
Traits§
- BinTuple
- Reshape the linear tuple type to a binary tree, either left associated or right associated.
- Convert
- Converts to another type. The purpose of this trait is for implementing
ConvertTuple
. - Convert
Tuple - Converts a tuple to another one, where the fields of the old tuple can be
Convert
-ed into the fiedls of the new tuple. SeeConvert
. - From
Tuple - Converts a tuple from another one, the fields of which can be converted into the fields of the new tuple.
- Homo
Tuple - Homogeneous Tuple’s trait.
- Into
Array - Converts a tuple into an array, where the fields of the tuple can be converted into the same type of the array element.
- Into
Boxed Slice - Converts a tuple into a boxed slice, where the fields of the tuple can be converted into the same type of the slice element.
- Into
Homo Tuple - Converts a heterogeneous tuple to a homogeneous one.
- Into
Tuple - Converts a tuple to a new one. This is the counterpart of
FromTuple
. - IntoVec
- Converts a tuple into a
Vec
, where the fields of the tuple can be converted into the same type of theVec
’s element. - Len
- Indicate the amount of the tuple’s fields.
- LenEq
- LenExceeds
- MapHomo
Tuple - The map adapter for homogeneous tuples
- NonZero
Len - Onion
- PopBack
- Removes the last field of the tuple.
- PopFront
- Removes the first field of the tuple.
- Push
Back - Adds a
Back
value to the tuple, as the last field. - Push
Front - Adds a
Front
value to the tuple, as the first field. - TupleOf
- A tuple is composed of
T
if all of its fields are values ofT
. SeeValueOf
. - ValueOf
- Marks that
Self
is a value ofT
. The purpose of this trait is for implementingTupleOf
.