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
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§
- Tuples which may be split at index
MIDDLE
have the trait TupleSplitAt, which, when split, returns TupleSplitAt::Left, TupleSplitAt::Right. - A trait for splitting a tuple up into two specific parts.
L
andR
must together concatinate toSelf
. - A trait for splitting a tuple up into two parts given a specified left part
L
.L
must be a leftmost segment ofSelf
. - A trait for splitting a tuple up into two parts given a specified right part
R
.R
must be a rightmost segment ofSelf
.
Functions§
- Splits tuple at a given index.
- Splits tuple into two given tuples.
Type Aliases§
- Type alias Left equals TupleSplit::Left for any tuple which implements TupleSplit at the given MIDDLE.
- Type alias Right equals TupleSplit::Right for any tuple which implements TupleSplit at the given MIDDLE.