4 releases

0.1.2 Nov 26, 2023
0.1.1 Mar 10, 2023
0.1.0 Nov 9, 2020
0.0.1 Nov 2, 2020

#148 in Rust patterns

Download history 18160/week @ 2024-06-14 23679/week @ 2024-06-21 17717/week @ 2024-06-28 19748/week @ 2024-07-05 24165/week @ 2024-07-12 27299/week @ 2024-07-19 25338/week @ 2024-07-26 23543/week @ 2024-08-02 36550/week @ 2024-08-09 24016/week @ 2024-08-16 30211/week @ 2024-08-23 35664/week @ 2024-08-30 32917/week @ 2024-09-06 29599/week @ 2024-09-13 33304/week @ 2024-09-20 22229/week @ 2024-09-27

125,834 downloads per month
Used in 11 crates (4 directly)

MIT/Apache

54KB
729 lines

Motivation

For tuple's type conversions.

Usage

Add this crate to Cargo.toml

Cargo.toml:

tuplex = "0.1"

Features

  1. adding/removing element at front/back

  2. converting heterogeneous tuples to homogeneous ones

Document

See the doc for more examples.

License

Licensed under APACHE-2.0 or MIT.


lib.rs:

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

No runtime deps

Features