tuplities_push_front/
lib.rs

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