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

Function default_init

crates/codegen/src/csharp.rs:1290–1319  ·  view source on GitHub ↗
(ctx: &TypespaceForGenerate, ty: &AlgebraicTypeUse)

Source from the content-addressed store, hash-verified

1288}
1289
1290fn default_init(ctx: &TypespaceForGenerate, ty: &AlgebraicTypeUse) -> Option<&'static str> {
1291 match ty {
1292 // Options (`T?`) have a default value of null which is fine for us.
1293 AlgebraicTypeUse::Option(_) => None,
1294 AlgebraicTypeUse::Ref(r) => match &ctx[*r] {
1295 // TODO: generate some proper default here (what would it be for tagged enums?).
1296 AlgebraicTypeDef::Sum(_) => Some("null!"),
1297 // Simple enums have their own default (variant with value of zero).
1298 AlgebraicTypeDef::PlainEnum(_) => None,
1299 AlgebraicTypeDef::Product(_) => Some("new()"),
1300 },
1301 // See Sum(_) handling above.
1302 AlgebraicTypeUse::ScheduleAt => Some("null!"),
1303 AlgebraicTypeUse::Array(_) => Some("new()"),
1304 // Strings must have explicit default value of "".
1305 AlgebraicTypeUse::String => Some(r#""""#),
1306 // Primitives are initialized to zero automatically.
1307 AlgebraicTypeUse::Primitive(_) => None,
1308 // Result<,> must be explicitly initialized.
1309 AlgebraicTypeUse::Result { .. } => Some("default!"),
1310 // these are structs, they are initialized to zero-filled automatically
1311 AlgebraicTypeUse::Unit
1312 | AlgebraicTypeUse::Identity
1313 | AlgebraicTypeUse::ConnectionId
1314 | AlgebraicTypeUse::Timestamp
1315 | AlgebraicTypeUse::TimeDuration
1316 | AlgebraicTypeUse::Uuid => None,
1317 AlgebraicTypeUse::Never => unimplemented!("never types are not yet supported in C# output"),
1318 }
1319}
1320
1321struct CsharpAutogen {
1322 output: CodeIndenter<String>,

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…