Skip to content

Commit

Permalink
Merge pull request #221 from hculea/andi_t/go-supports-generics
Browse files Browse the repository at this point in the history
Make changes required for Go translation to support generics
  • Loading branch information
AndyTitu authored Dec 30, 2024
2 parents b6e6bf1 + c7f8e0f commit d8ba388
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/src/language/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl Language for Go {
&self.type_mappings
}

fn format_generic_parameters(&mut self, parameters: Vec<String>) -> String {
format!("[{}]", parameters.join(", "))
}

fn format_special_type(
&mut self,
special_ty: &SpecialRustType,
Expand Down Expand Up @@ -187,10 +191,21 @@ impl Language for Go {

fn write_struct(&mut self, w: &mut dyn Write, rs: &RustStruct) -> std::io::Result<()> {
write_comments(w, 0, &rs.comments)?;
// TODO: Support generic bounds: https://github.com/1Password/typeshare/issues/222
writeln!(
w,
"type {} struct {{",
self.acronyms_to_uppercase(&rs.id.renamed)
"type {}{} struct {{",
self.acronyms_to_uppercase(&rs.id.renamed),
(!rs.generic_types.is_empty())
.then(|| format!(
"[{}]",
rs.generic_types
.iter()
.map(|ty| format!("{} any", ty))
.collect::<Vec<String>>()
.join(", ")
))
.unwrap_or_default()
)?;

rs.fields
Expand Down

0 comments on commit d8ba388

Please sign in to comment.