vy_core/
either.rs

1use crate::{Buffer, IntoHtml};
2
3macro_rules! impl_enum {
4    ( $( $name:ident $($var:ident)+, )+ ) => {
5        $(
6            pub enum $name<$($var),+> {
7                $($var($var)),+
8            }
9
10            impl<$($var),+> IntoHtml for $name<$($var),+>
11            where
12                $($var: IntoHtml),+
13            {
14                #[inline]
15                fn into_html(self) -> impl IntoHtml {
16                    match self {
17                        $( $name::$var(value) => $name::$var(value.into_html()), )*
18                    }
19                }
20
21                #[inline]
22                fn escape_and_write(self, buf: &mut Buffer) {
23                    match self {
24                        $( $name::$var(value) => value.escape_and_write(buf), )*
25                    }
26                }
27
28                #[inline]
29                fn size_hint(&self) -> usize {
30                    match self {
31                        $( $name::$var(value) => value.size_hint(), )*
32                    }
33                }
34            }
35        )*
36    };
37}
38
39impl_enum! {
40    Either A B,
41    Either3 A B C,
42    Either4 A B C D,
43    Either5 A B C D E,
44    Either6 A B C D E F,
45    Either7 A B C D E F G,
46    Either8 A B C D E F G H,
47    Either9 A B C D E F G H I,
48}