tuplities_push_back/
lib.rs

1#![no_std]
2
3//! [tuplities](https://github.com/lucacappelletti94/tuplities) suite crate providing the `TuplePushBack` trait.
4
5#[tuplities_derive::impl_push_back]
6/// A trait for tuples that allows pushing an element to the back.
7pub trait TuplePushBack<T> {
8    /// The type of the tuple after adding `T` to the back.
9    type Output;
10
11    /// Consumes the tuple and appends the given value, returning the new tuple.
12    ///
13    /// # Examples
14    ///
15    /// ```rust
16    /// use tuplities_push_back::TuplePushBack;
17    ///
18    /// let tuple = ("hello",);
19    /// let new_tuple = tuple.push_back("world");
20    /// assert_eq!(new_tuple, ("hello", "world"));
21    /// ```
22    ///
23    /// Part of the [`tuplities`](https://docs.rs/tuplities/latest/tuplities/) crate.
24    fn push_back(self, value: T) -> Self::Output;
25}
26
27#[cfg(test)]
28mod tests {
29    use super::TuplePushBack;
30
31    #[test]
32    fn test_push_back_zero_sized_tuple() {
33        let tuple = ();
34        let result = tuple.push_back(42);
35        // Check that the type is correct: () + i32 = (i32,)
36        let expected: (i32,) = (42,);
37        assert_eq!(result, expected);
38    }
39}