Skip to content

Commit

Permalink
feat(rust): add support for external types
Browse files Browse the repository at this point in the history
  • Loading branch information
w4bremer committed Jul 9, 2024
1 parent fa03ada commit 513b1e2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/gen/filters/filterrs/extern.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package filterrs

import (
"github.com/apigear-io/cli/pkg/model"
)

type RsExtern struct {
Name string
Crate string
Version string
}

func parseRsExtern(schema *model.Schema) RsExtern {
xe := schema.GetExtern()
return rsExtern(xe)
}

func rsExtern(xe *model.Extern) RsExtern {
name := xe.Meta.GetString("rs.type")
crate := xe.Meta.GetString("rs.crate")
version := xe.Meta.GetString("rs.version")
if name == "" {
name = xe.Name
}
return RsExtern{
Name: name,
Crate: crate,
Version: version,
}
}
1 change: 1 addition & 0 deletions pkg/gen/filters/filterrs/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ func PopulateFuncMap(fm template.FuncMap) {
fm["rsVars"] = rsVars
fm["rsType"] = rsType
fm["rsTypeRef"] = rsTypeRef
fm["rsExtern"] = rsExtern
}
4 changes: 4 additions & 0 deletions pkg/gen/filters/filterrs/rs_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func ToParamString(prefixVarName string, prefixComplexType string, schema *model
case "bool":
return fmt.Sprintf("%s: bool", name), nil
}
ex := schema.LookupExtern(schema.Import, schema.Type)
if ex != nil {
return fmt.Sprintf("%s: &%s", name, rsExtern(schema.GetExtern()).Name), nil
}
e := schema.LookupEnum(schema.Import, schema.Type)
if e != nil {
return fmt.Sprintf("%s: %sEnum", name, e.Name), nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/gen/filters/filterrs/rs_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func ToReturnString(prefixComplexType string, schema *model.Schema) (string, err
case "bool":
text = "bool"
default:
xe := schema.LookupExtern(schema.Import, schema.Type)
if xe != nil {
text = rsExtern(schema.GetExtern()).Name
}
e := schema.LookupEnum(schema.Import, schema.Type)
if e != nil {
text = fmt.Sprintf("%s%sEnum", prefixComplexType, e.Name)
Expand Down
4 changes: 4 additions & 0 deletions pkg/gen/filters/filterrs/rs_type_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func ToTypeRefString(prefix string, schema *model.Schema) (string, error) {
case "bool":
text = "bool"
default:
ex := schema.LookupExtern(schema.Import, schema.Type)
if ex != nil {
return fmt.Sprintf("&%s%s", prefix, rsExtern(schema.GetExtern()).Name), nil
}
e := schema.LookupEnum(schema.Import, schema.Type)
if e != nil {
text = fmt.Sprintf("%s%sEnum", prefix, e.Name)
Expand Down

0 comments on commit 513b1e2

Please sign in to comment.