#tuple #traits #split #const #tupleops

nightly no-std tuple_split

An extension for the tupleops crate which adds a trait for splitting tuples by an index

2 releases

0.1.1 Mar 20, 2023
0.1.0 Mar 20, 2023

#98 in #tuple


Used in currycompose

MIT license

8KB
66 lines

This crate an extension for the tupleops crate, which adds a trait for splitting tuples by an index.


lib.rs:

This crate is an extension for the tupleops crate, which adds a trait for splitting tuples by index.

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

Type alias Left and Right equal TupleSplit::Left and TupleSplit::Right respectively. fpr any tuple which implements TupleSplit at the given MIDDLE.

The trait alias SplitLeftInto is implemented for any tuple which may be split where TupleSplit::Left = L.

The trait alias SplitRightInto is implemented for any tuple which may be split where TupleSplit::Right = R.

The trait alias SplitInto is implemented for any tuple which may be split where TupleSplit::Left = L and TupleSplit::Right = R.

use tupleops::concat_tuples;
use tuple_split::*;

let t: (u8, f32, &str) = (1, 1.0, "test");

let (l, r): ((u8, f32), (&str,)) = TupleSplit::<2>::split_tuple(t);

assert_eq!(t, concat_tuples(l, r));

let (l, r): ((u8, f32), (&str,)) = split_tuple::<2, _>(t);

assert_eq!(t, concat_tuples(l, r));

Dependencies

~1.5MB
~38K SLoC