bon_macros/normalization/
syntax_variant.rs

1/// Struct, that contains both the original syntax (unprocessed) and the normalized
2/// version. This is useful for code that needs access to both versions of the syntax.
3#[derive(Debug)]
4pub(crate) struct SyntaxVariant<T> {
5    /// Original syntax that was passed to the macro without any modifications.
6    pub(crate) orig: T,
7
8    /// The value that is equivalent to `orig`, but it underwent normalization.
9    pub(crate) norm: T,
10}
11
12impl<T> SyntaxVariant<T> {
13    pub(crate) fn apply_ref<'a, U>(&'a self, f: impl Fn(&'a T) -> U) -> SyntaxVariant<U> {
14        let orig = f(&self.orig);
15        let norm = f(&self.norm);
16        SyntaxVariant { orig, norm }
17    }
18
19    pub(crate) fn into_iter(self) -> impl Iterator<Item = SyntaxVariant<T::Item>>
20    where
21        T: IntoIterator,
22    {
23        self.orig
24            .into_iter()
25            .zip(self.norm)
26            .map(|(orig, norm)| SyntaxVariant { orig, norm })
27    }
28}