tuplities_insert/lib.rs
1//! A trait for inserting elements at specific indices into tuples.
2//!
3//! This crate provides the `TupleInsert<Idx, T>` trait, which allows inserting an element
4//! at a compile-time known index into a tuple, returning the tuple with the element inserted.
5
6#![no_std]
7
8/// A trait for inserting an element at a specific index into a tuple.
9///
10/// This trait allows inserting an element at compile-time known index `Idx`
11/// into a tuple, returning the tuple with the element inserted.
12///
13/// # Examples
14///
15/// ```
16/// use tuplities_insert::TupleInsert;
17/// use typenum::U1;
18///
19/// let tuple = (1, 3.14);
20/// let inserted = TupleInsert::<U1, _>::insert(tuple, "hello");
21/// assert_eq!(inserted, (1, "hello", 3.14));
22/// ```
23#[tuplities_derive::impl_insert]
24pub trait TupleInsert<Idx: typenum::Unsigned, T> {
25 /// The type of the tuple after inserting the element.
26 type Output;
27
28 /// Inserts the element at index `Idx` into the tuple.
29 ///
30 /// Returns the tuple with the element inserted at the specified index.
31 fn insert(self, value: T) -> Self::Output;
32}