#![no_std]
#[tuplities_derive::impl_split]
pub trait TupleSplit<Idx> {
type Left;
type Right;
fn split(self) -> (Self::Left, Self::Right);
}
#[cfg(test)]
mod tests {
use super::TupleSplit;
use typenum::{U0, U1, U2, U3};
#[test]
fn test_split_at_zero() {
let tuple = (1, 2, 3);
let (left, right) = TupleSplit::<U0>::split(tuple);
assert_eq!(left, ());
assert_eq!(right, (1, 2, 3));
}
#[test]
fn test_split_at_middle() {
let tuple = (1, 2, 3, 4);
let (left, right) = TupleSplit::<U2>::split(tuple);
assert_eq!(left, (1, 2));
assert_eq!(right, (3, 4));
}
#[test]
fn test_split_at_end() {
let tuple = (1, 2, 3);
let (left, right) = TupleSplit::<U3>::split(tuple);
assert_eq!(left, (1, 2, 3));
assert_eq!(right, ());
}
#[test]
fn test_split_empty_tuple() {
let tuple = ();
let (left, right) = TupleSplit::<U0>::split(tuple);
assert_eq!(left, ());
assert_eq!(right, ());
}
#[test]
fn test_split_single_element_at_zero() {
let tuple = (42,);
let (left, right) = TupleSplit::<U0>::split(tuple);
assert_eq!(left, ());
assert_eq!(right, (42,));
}
#[test]
fn test_split_single_element_at_one() {
let tuple = (42,);
let (left, right) = TupleSplit::<U1>::split(tuple);
assert_eq!(left, (42,));
assert_eq!(right, ());
}
#[test]
fn test_split_two_elements_at_zero() {
let tuple = (1, 2);
let (left, right) = TupleSplit::<U0>::split(tuple);
assert_eq!(left, ());
assert_eq!(right, (1, 2));
}
#[test]
fn test_split_two_elements_at_one() {
let tuple = (1, 2);
let (left, right) = TupleSplit::<U1>::split(tuple);
assert_eq!(left, (1,));
assert_eq!(right, (2,));
}
#[test]
fn test_split_two_elements_at_two() {
let tuple = (1, 2);
let (left, right) = TupleSplit::<U2>::split(tuple);
assert_eq!(left, (1, 2));
assert_eq!(right, ());
}
}