Generate a file which defines an `enum` corresponding to the `sum_type`.
(
module: &ModuleDef,
out: &mut Indenter,
name: &str,
variants: &[(Identifier, AlgebraicTypeUse)],
is_plain: bool,
)
| 959 | |
| 960 | /// Generate a file which defines an `enum` corresponding to the `sum_type`. |
| 961 | pub fn define_enum_for_sum( |
| 962 | module: &ModuleDef, |
| 963 | out: &mut Indenter, |
| 964 | name: &str, |
| 965 | variants: &[(Identifier, AlgebraicTypeUse)], |
| 966 | is_plain: bool, |
| 967 | ) { |
| 968 | print_enum_derives(out); |
| 969 | if is_plain { |
| 970 | print_plain_enum_extra_derives(out); |
| 971 | } |
| 972 | write!(out, "pub enum {name} "); |
| 973 | |
| 974 | out.delimited_block( |
| 975 | "{", |
| 976 | |out| { |
| 977 | for (ident, ty) in variants { |
| 978 | write_enum_variant(module, out, ident, ty); |
| 979 | out.newline(); |
| 980 | } |
| 981 | }, |
| 982 | "}\n", |
| 983 | ); |
| 984 | |
| 985 | out.newline() |
| 986 | } |
| 987 | |
| 988 | fn write_enum_variant(module: &ModuleDef, out: &mut Indenter, ident: &Identifier, ty: &AlgebraicTypeUse) { |
| 989 | let name = ident.deref().to_case(Case::Pascal); |
no test coverage detected
searching dependent graphs…