Crate tuple_split

Source
Expand description

This crate an extension for the tupleops crate.

tupleops contains many useful features for manipulating tuples andusing tuples in generic code. However, it does not support any kind of splitting of tuples. This crate adds that feature.

§Examples

Tuples which may be split at index MIDDLE have the trait TupleSplit, which, when split, returns (TupleSplit::Left, TupleSplit::Right).

They can lso be split by specifying either of the sides or both.

let t: (u8, f32, &str) = (32, 0.707, "test");

// Splitting tuples by index
let (l, r): ((), (u8, f32, &str)) = tuple_split::split_tuple_at::<0, _>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

let (l, r): ((u8,), (f32, &str)) = tuple_split::split_tuple_at::<1, _>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

let (l, r): ((u8, f32), (&str,)) = tuple_split::split_tuple_at::<2, _>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

let (l, r): ((u8, f32, &str), ()) = tuple_split::split_tuple_at::<3, _>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

// Splitting tuples given a left side
let (l, r): ((u8, f32), (&str,)) = tuple_split::split_tuple_into_left::<(u8, f32)>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

// Splitting tuples given a right side
let (l, r): ((u8, f32), (&str,)) = tuple_split::split_tuple_into_right::<(&str,)>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

// Splitting tuples given both sides
let (l, r): ((u8, f32), (&str,)) = tuple_split::split_tuple_into::<(u8, f32), (&str)>(t);
assert_eq!(t, tupleops::concat_tuples(l, r));

Traits§

Functions§

Type Aliases§