1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
use paste::paste; macro_rules! impl_cell { ($name:ident $($variant:ident)+) => { paste! { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))] pub enum $name<$($variant),+> { $($variant($variant)),+ } impl<$($variant),+> $name<$($variant),+> { $( pub fn [<is_ $variant:snake>](&self) -> bool { matches!(self, Self::$variant(_)) } pub fn [<as_ $variant:snake>](&self) -> Option<&$variant> { match self { Self::$variant(x) => Some(x), _ => None, } } pub fn [<as_mut_ $variant:snake>](&mut self) -> Option<&mut $variant> { match self { Self::$variant(x) => Some(x), _ => None, } } pub fn [<into_ $variant:snake>](self) -> Option<$variant> { match self { Self::$variant(x) => Some(x), _ => None, } } )+ } } }; } impl_cell!(Cell2 A B); impl_cell!(Cell3 A B C); impl_cell!(Cell4 A B C D); impl_cell!(Cell5 A B C D E); impl_cell!(Cell6 A B C D E F); impl_cell!(Cell7 A B C D E F G); impl_cell!(Cell8 A B C D E F G H); impl_cell!(Cell9 A B C D E F G H I); impl_cell!(Cell10 A B C D E F G H I J); impl_cell!(Cell11 A B C D E F G H I J K); impl_cell!(Cell12 A B C D E F G H I J K L); impl_cell!(Cell13 A B C D E F G H I J K L M); impl_cell!(Cell14 A B C D E F G H I J K L M N); impl_cell!(Cell15 A B C D E F G H I J K L M N O); impl_cell!(Cell16 A B C D E F G H I J K L M N O P); impl_cell!(Cell17 A B C D E F G H I J K L M N O P Q); impl_cell!(Cell18 A B C D E F G H I J K L M N O P Q R); impl_cell!(Cell19 A B C D E F G H I J K L M N O P Q R S); impl_cell!(Cell20 A B C D E F G H I J K L M N O P Q R S T); impl_cell!(Cell21 A B C D E F G H I J K L M N O P Q R S T U); impl_cell!(Cell22 A B C D E F G H I J K L M N O P Q R S T U V); impl_cell!(Cell23 A B C D E F G H I J K L M N O P Q R S T U V W); impl_cell!(Cell24 A B C D E F G H I J K L M N O P Q R S T U V W X); impl_cell!(Cell25 A B C D E F G H I J K L M N O P Q R S T U V W X Y); impl_cell!(Cell26 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);