MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / define_enum_for_sum

Function define_enum_for_sum

crates/codegen/src/rust.rs:961–986  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

959
960/// Generate a file which defines an `enum` corresponding to the `sum_type`.
961pub 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
988fn write_enum_variant(module: &ModuleDef, out: &mut Indenter, ident: &Identifier, ty: &AlgebraicTypeUse) {
989 let name = ident.deref().to_case(Case::Pascal);

Callers 1

generate_type_filesMethod · 0.85

Calls 5

print_enum_derivesFunction · 0.85
write_enum_variantFunction · 0.85
delimited_blockMethod · 0.80
newlineMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…