in serde-generate/src/golang.rs [546:596]
fn output_variant(
&mut self,
base: &str,
index: u32,
name: &str,
variant: &VariantFormat,
) -> Result<()> {
use VariantFormat::*;
let fields = match variant {
Unit => Vec::new(),
NewType(format) => match format.as_ref() {
// We cannot define a "new type" (e.g. `type Foo Bar`) out of a typename `Bar` because `Bar`
// could point to a Go interface. This would make `Foo` an interface as well. Interfaces can't be used
// as structs (e.g. they cannot have methods).
//
// Similarly, option types are compiled as pointers but `type Foo *Bar` would prevent `Foo` from being a
// valid pointer receiver.
Format::TypeName(_) | Format::Option(_) => vec![Named {
name: "Value".to_string(),
value: format.as_ref().clone(),
}],
// Other cases are fine.
_ => {
self.output_struct_or_variant_new_type_container(
Some(base),
Some(index),
name,
format,
)?;
return Ok(());
}
},
Tuple(formats) => formats
.iter()
.enumerate()
.map(|(i, f)| Named {
name: format!("Field{}", i),
value: f.clone(),
})
.collect(),
Struct(fields) => fields
.iter()
.map(|f| Named {
name: f.name.to_camel_case(),
value: f.value.clone(),
})
.collect(),
Variable(_) => panic!("incorrect value"),
};
self.output_struct_or_variant_container(Some(base), Some(index), name, &fields)
}