Skip to content

Commit c3ee2ad

Browse files
authored
Merge pull request #134 from 1Password/CerulanLumina/133-smart-pointers
Support smart pointers
2 parents bcfa2c3 + baf8c1a commit c3ee2ad

File tree

15 files changed

+455
-188
lines changed

15 files changed

+455
-188
lines changed

core/data/tests/boxed_value/input.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

core/data/tests/boxed_value/output.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

core/data/tests/boxed_value/output.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

core/data/tests/boxed_value/output.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

core/data/tests/boxed_value/output.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

core/data/tests/boxed_value/output.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// This is a comment.
2+
#[typeshare]
3+
#[serde(tag = "type", content = "content")]
4+
pub enum BoxyColors {
5+
Red,
6+
Blue,
7+
Green(Box<String>),
8+
}
9+
10+
/// This is a comment.
11+
#[typeshare]
12+
#[serde(tag = "type", content = "content")]
13+
pub struct ArcyColors {
14+
pub red: Weak<u8>,
15+
pub blue: ArcWeak<String>,
16+
pub green: Arc<Vec<String>>,
17+
}
18+
19+
/// This is a comment.
20+
#[typeshare]
21+
#[serde(tag = "type", content = "content")]
22+
pub struct MutexyColors {
23+
pub blue: Mutex<Vec<String>>,
24+
pub green: Mutex<String>,
25+
}
26+
27+
/// This is a comment.
28+
#[typeshare]
29+
#[serde(tag = "type", content = "content")]
30+
pub struct RcyColors {
31+
pub red: RcWeak<String>,
32+
pub blue: Rc<Vec<String>>,
33+
pub green: Rc<String>,
34+
}
35+
36+
/// This is a comment.
37+
#[typeshare]
38+
#[serde(tag = "type", content = "content")]
39+
pub struct CellyColors {
40+
pub red: Cell<String>,
41+
pub blue: RefCell<Vec<String>>,
42+
}
43+
44+
/// This is a comment.
45+
#[typeshare]
46+
#[serde(tag = "type", content = "content")]
47+
pub struct LockyColors {
48+
pub red: RwLock<String>,
49+
}
50+
51+
/// This is a comment.
52+
#[typeshare]
53+
#[serde(tag = "type", content = "content")]
54+
pub struct CowyColors<'a> {
55+
pub lifetime: Cow<'a, str>,
56+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package proto
2+
3+
import "encoding/json"
4+
5+
// This is a comment.
6+
type ArcyColors struct {
7+
Red int `json:"red"`
8+
Blue string `json:"blue"`
9+
Green []string `json:"green"`
10+
}
11+
// This is a comment.
12+
type MutexyColors struct {
13+
Blue []string `json:"blue"`
14+
Green string `json:"green"`
15+
}
16+
// This is a comment.
17+
type RcyColors struct {
18+
Red string `json:"red"`
19+
Blue []string `json:"blue"`
20+
Green string `json:"green"`
21+
}
22+
// This is a comment.
23+
type CellyColors struct {
24+
Red string `json:"red"`
25+
Blue []string `json:"blue"`
26+
}
27+
// This is a comment.
28+
type LockyColors struct {
29+
Red string `json:"red"`
30+
}
31+
// This is a comment.
32+
type CowyColors struct {
33+
Lifetime string `json:"lifetime"`
34+
}
35+
// This is a comment.
36+
type BoxyColorsTypes string
37+
const (
38+
BoxyColorsTypeVariantRed BoxyColorsTypes = "Red"
39+
BoxyColorsTypeVariantBlue BoxyColorsTypes = "Blue"
40+
BoxyColorsTypeVariantGreen BoxyColorsTypes = "Green"
41+
)
42+
type BoxyColors struct{
43+
Type BoxyColorsTypes `json:"type"`
44+
content interface{}
45+
}
46+
47+
func (b *BoxyColors) UnmarshalJSON(data []byte) error {
48+
var enum struct {
49+
Tag BoxyColorsTypes `json:"type"`
50+
Content json.RawMessage `json:"content"`
51+
}
52+
if err := json.Unmarshal(data, &enum); err != nil {
53+
return err
54+
}
55+
56+
b.Type = enum.Tag
57+
switch b.Type {
58+
case BoxyColorsTypeVariantRed:
59+
return nil
60+
case BoxyColorsTypeVariantBlue:
61+
return nil
62+
case BoxyColorsTypeVariantGreen:
63+
var res string
64+
b.content = &res
65+
66+
}
67+
if err := json.Unmarshal(enum.Content, &b.content); err != nil {
68+
return err
69+
}
70+
71+
return nil
72+
}
73+
74+
func (b BoxyColors) MarshalJSON() ([]byte, error) {
75+
var enum struct {
76+
Tag BoxyColorsTypes `json:"type"`
77+
Content interface{} `json:"content,omitempty"`
78+
}
79+
enum.Tag = b.Type
80+
enum.Content = b.content
81+
return json.Marshal(enum)
82+
}
83+
84+
func (b BoxyColors) Green() string {
85+
res, _ := b.content.(*string)
86+
return *res
87+
}
88+
89+
func NewBoxyColorsTypeVariantRed() BoxyColors {
90+
return BoxyColors{
91+
Type: BoxyColorsTypeVariantRed,
92+
}
93+
}
94+
func NewBoxyColorsTypeVariantBlue() BoxyColors {
95+
return BoxyColors{
96+
Type: BoxyColorsTypeVariantBlue,
97+
}
98+
}
99+
func NewBoxyColorsTypeVariantGreen(content string) BoxyColors {
100+
return BoxyColors{
101+
Type: BoxyColorsTypeVariantGreen,
102+
content: &content,
103+
}
104+
}
105+

0 commit comments

Comments
 (0)