xref: /third_party/rust/crates/syn/src/gen_helper.rs (revision fad3a1d3)
1#[cfg(feature = "fold")]
2pub(crate) mod fold {
3    use crate::punctuated::{Pair, Punctuated};
4
5    pub(crate) trait FoldHelper {
6        type Item;
7        fn lift<F>(self, f: F) -> Self
8        where
9            F: FnMut(Self::Item) -> Self::Item;
10    }
11
12    impl<T> FoldHelper for Vec<T> {
13        type Item = T;
14        fn lift<F>(self, f: F) -> Self
15        where
16            F: FnMut(Self::Item) -> Self::Item,
17        {
18            self.into_iter().map(f).collect()
19        }
20    }
21
22    impl<T, U> FoldHelper for Punctuated<T, U> {
23        type Item = T;
24        fn lift<F>(self, mut f: F) -> Self
25        where
26            F: FnMut(Self::Item) -> Self::Item,
27        {
28            self.into_pairs()
29                .map(Pair::into_tuple)
30                .map(|(t, u)| Pair::new(f(t), u))
31                .collect()
32        }
33    }
34}
35