hlist2/ops/
prepend.rs

1use crate::{Cons, HList};
2
3/// Prepend new element to the heterogenous list.
4pub trait Prepend: HList {
5    /// Type of heterogenous list with new element.
6    type Output<T>: HList;
7
8    /// Prepends new element to the heterogenous list.
9    ///
10    /// New element will be placed at the beginning of the heterogenous list,
11    /// resulting in new heterogenous list.
12    ///
13    /// # Examples
14    ///
15    /// ```
16    /// use hlist2::{hlist, ops::Prepend};
17    ///
18    /// let list = hlist![2.0, true, "hello world"];
19    /// assert_eq!(list.prepend(1), hlist![1, 2.0, true, "hello world"]);
20    /// ```
21    #[doc(alias("push_front"))]
22    fn prepend<T>(self, value: T) -> Self::Output<T>;
23}
24
25impl<L> Prepend for L
26where
27    L: HList,
28{
29    type Output<T> = Cons<T, L>;
30
31    fn prepend<T>(self, value: T) -> Self::Output<T> {
32        Cons(value, self)
33    }
34}