Skip to content

Instantly share code, notes, and snippets.

@piksel
Created December 13, 2022 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piksel/698569df54626c02da604da88c8c287d to your computer and use it in GitHub Desktop.
Save piksel/698569df54626c02da604da88c8c287d to your computer and use it in GitHub Desktop.
rust vs go
func (MarkdownTreeRenderer) writeFieldExtras(sb *strings.Builder, field *FieldInfo) {
if len(field.Keys) > 1 {
sb.WriteString(" Aliases: `")
for i, key := range field.Keys {
if i == 0 {
// Skip primary alias (as it's the same as the field name)
continue
}
if i > 1 {
sb.WriteString("`, `")
}
sb.WriteString(key)
}
sb.WriteString("` \n")
}
if field.EnumFormatter != nil {
sb.WriteString(" Possible values: `")
for i, name := range field.EnumFormatter.Names() {
if i != 0 {
sb.WriteString("`, `")
}
sb.WriteString(name)
}
sb.WriteString("` \n")
}
}
fn write_field_extras(&self, output: &mut String, prop: &spec::SpecProp) -> eyre::Result<()> {
// Skip primary alias (as it's the same as the field name)
if let Some((_, rest)) = prop.keys.split_first() {
writeln!(output, " Aliases: `{}` ", rest.join("`,`"))?;
}
if let PropType::Option(opt) = prop.prop_type {
writeln!(output, " Possible values: `{}` ", opt.values.join("`,`"))?;
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment