Crate tuplex

source ·
Expand description

Rust tuple extension.

Features

  1. adding/removing element at front/back

  2. converting heterogeneous tuples to homogeneous ones

  3. 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

  1. 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

  • Denotes a tuple type, the fields of which are of the same type. Up to 32 fields.

Structs

Traits

  • Reshape the linear tuple type to a binary tree, either left associated or right associated.
  • Converts to another type. The purpose of this trait is for implementing ConvertTuple.
  • Converts a tuple to another one, where the fields of the old tuple can be Convert-ed into the fiedls of the new tuple. See Convert.
  • Converts a tuple from another one, the fields of which can be converted into the fields of the new tuple.
  • Homogeneous Tuple’s trait.
  • Converts a tuple into an array, where the fields of the tuple can be converted into the same type of the array element.
  • Converts a tuple into a boxed slice, where the fields of the tuple can be converted into the same type of the slice element.
  • Converts a heterogeneous tuple to a homogeneous one.
  • Converts a tuple to a new one. This is the counterpart of FromTuple.
  • Converts a tuple into a Vec, where the fields of the tuple can be converted into the same type of the Vec’s element.
  • Indicate the amount of the tuple’s fields.
  • The map adapter for homogeneous tuples
  • Removes the last field of the tuple.
  • Removes the first field of the tuple.
  • Adds a Back value to the tuple, as the last field.
  • Adds a Front value to the tuple, as the first field.
  • A tuple is composed of T if all of its fields are values of T. See ValueOf.
  • Marks that Self is a value of T. The purpose of this trait is for implementing TupleOf.