gesha_rust_types/
enum_variant.rs

1use crate::{DataType, EnumVariantName};
2use std::fmt::{Display, Formatter};
3
4/// rf. https://doc.rust-lang.org/reference/items/enumerations.html
5#[derive(Clone, Debug, Hash, Eq, PartialEq)]
6pub struct EnumVariant {
7    pub name: EnumVariantName,
8    pub attributes: Vec<EnumVariantAttribute>,
9    pub case: EnumCase,
10    _hide_default_constructor: bool,
11}
12
13impl EnumVariant {
14    pub fn unit(name: EnumVariantName, attributes: Vec<EnumVariantAttribute>) -> Self {
15        EnumVariant {
16            name,
17            attributes,
18            case: EnumCase::Unit,
19            _hide_default_constructor: true,
20        }
21    }
22    pub fn tuple(
23        name: EnumVariantName,
24        types: Vec<DataType>,
25        attributes: Vec<EnumVariantAttribute>,
26    ) -> Self {
27        EnumVariant {
28            name,
29            attributes,
30            case: EnumCase::Tuple(types),
31            _hide_default_constructor: true,
32        }
33    }
34}
35
36#[derive(Clone, Debug, Hash, Eq, PartialEq)]
37pub enum EnumCase {
38    Unit,
39    Tuple(Vec<DataType>),
40}
41
42#[derive(Clone, Debug, Hash, Eq, PartialEq)]
43pub struct EnumVariantAttribute(String);
44
45impl EnumVariantAttribute {
46    pub fn new<A: Into<String>>(a: A) -> Self {
47        Self(a.into())
48    }
49}
50
51impl Display for EnumVariantAttribute {
52    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
53        Display::fmt(&self.0, f)
54    }
55}