-
Notifications
You must be signed in to change notification settings - Fork 1
/
rs_return.go
60 lines (56 loc) · 1.25 KB
/
rs_return.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package filterrs
import (
"fmt"
"github.com/apigear-io/cli/pkg/model"
)
func ToReturnString(prefixComplexType string, schema *model.Schema) (string, error) {
t := schema.Type
text := ""
switch t {
case "void":
text = "()"
case "string":
text = "String"
case "int":
text = "i32"
case "int32":
text = "i32"
case "int64":
text = "i64"
case "float":
text = "f32"
case "float32":
text = "f32"
case "float64":
text = "f64"
case "bool":
text = "bool"
default:
if schema.Module == nil {
return "xxx", fmt.Errorf("schema.Module is nil")
}
e := schema.Module.LookupEnum(t)
if e != nil {
text = fmt.Sprintf("%s%sEnum", prefixComplexType, e.Name)
}
s := schema.Module.LookupStruct(t)
if s != nil {
text = fmt.Sprintf("%s%s", prefixComplexType, s.Name)
}
i := schema.Module.LookupInterface(t)
if i != nil {
text = fmt.Sprintf("&%s%s", prefixComplexType, i.Name)
}
}
if schema.IsArray {
return fmt.Sprintf("Vec<%s>", text), nil
}
return text, nil
}
// cast value to TypedNode and deduct the rs return type
func rsReturn(prefixComplexType string, node *model.TypedNode) (string, error) {
if node == nil {
return "xxx", fmt.Errorf("rsReturn node is nil")
}
return ToReturnString(prefixComplexType, &node.Schema)
}