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

Function write_enum_variant

crates/codegen/src/rust.rs:988–1005  ·  view source on GitHub ↗
(module: &ModuleDef, out: &mut Indenter, ident: &Identifier, ty: &AlgebraicTypeUse)

Source from the content-addressed store, hash-verified

986}
987
988fn write_enum_variant(module: &ModuleDef, out: &mut Indenter, ident: &Identifier, ty: &AlgebraicTypeUse) {
989 let name = ident.deref().to_case(Case::Pascal);
990 write!(out, "{name}");
991
992 // If the contained type is the unit type, i.e. this variant has no members,
993 // write it without parens or braces, like
994 // ```
995 // Foo,
996 // ```
997 if !matches!(ty, AlgebraicTypeUse::Unit) {
998 // If the contained type is not a product, i.e. this variant has a single
999 // member, write it tuple-style, with parens.
1000 write!(out, "(");
1001 write_type(module, out, ty).unwrap();
1002 write!(out, ")");
1003 }
1004 writeln!(out, ",");
1005}
1006
1007fn write_struct_type_fields_in_braces(
1008 module: &ModuleDef,

Callers 1

define_enum_for_sumFunction · 0.85

Calls 4

to_caseMethod · 0.80
write_typeFunction · 0.70
derefMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…