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

Method write_variant

crates/pg/src/encoder.rs:142–166  ·  view source on GitHub ↗
(
        &mut self,
        tag: u8,
        ty: PsqlType,
        name: Option<&str>,
        value: ValueWithType<AlgebraicValue>,
    )

Source from the content-addressed store, hash-verified

140 }
141
142 fn write_variant(
143 &mut self,
144 tag: u8,
145 ty: PsqlType,
146 name: Option<&str>,
147 value: ValueWithType<AlgebraicValue>,
148 ) -> Result<(), Self::Error> {
149 // Is a simple enum?
150 if let AlgebraicType::Sum(sum) = &ty.field.algebraic_type
151 && sum.is_simple_enum()
152 && let Some(variant_name) = name
153 {
154 self.encoder.encode_field(&variant_name)?;
155 return Ok(());
156 }
157
158 let PsqlChars { start, sep, end, quote } = ty.client.format_chars();
159 let name = name.map(Cow::from).unwrap_or_else(|| Cow::from(tag.to_string()));
160 let json = format!(
161 "{start}{quote}{name}{quote}{sep} {}{end}",
162 satn::PsqlWrapper { ty, value }
163 );
164 self.encoder.encode_field(&json)?;
165 Ok(())
166 }
167}
168
169#[cfg(test)]

Callers

nothing calls this directly

Calls 5

is_simple_enumMethod · 0.80
format_charsMethod · 0.80
OkFunction · 0.50
mapMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected