-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from 1Password/CerulanLumina/133-smart-pointers
Support smart pointers
- Loading branch information
Showing
15 changed files
with
455 additions
and
188 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub enum BoxyColors { | ||
Red, | ||
Blue, | ||
Green(Box<String>), | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct ArcyColors { | ||
pub red: Weak<u8>, | ||
pub blue: ArcWeak<String>, | ||
pub green: Arc<Vec<String>>, | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct MutexyColors { | ||
pub blue: Mutex<Vec<String>>, | ||
pub green: Mutex<String>, | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct RcyColors { | ||
pub red: RcWeak<String>, | ||
pub blue: Rc<Vec<String>>, | ||
pub green: Rc<String>, | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct CellyColors { | ||
pub red: Cell<String>, | ||
pub blue: RefCell<Vec<String>>, | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct LockyColors { | ||
pub red: RwLock<String>, | ||
} | ||
|
||
/// This is a comment. | ||
#[typeshare] | ||
#[serde(tag = "type", content = "content")] | ||
pub struct CowyColors<'a> { | ||
pub lifetime: Cow<'a, str>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package proto | ||
|
||
import "encoding/json" | ||
|
||
// This is a comment. | ||
type ArcyColors struct { | ||
Red int `json:"red"` | ||
Blue string `json:"blue"` | ||
Green []string `json:"green"` | ||
} | ||
// This is a comment. | ||
type MutexyColors struct { | ||
Blue []string `json:"blue"` | ||
Green string `json:"green"` | ||
} | ||
// This is a comment. | ||
type RcyColors struct { | ||
Red string `json:"red"` | ||
Blue []string `json:"blue"` | ||
Green string `json:"green"` | ||
} | ||
// This is a comment. | ||
type CellyColors struct { | ||
Red string `json:"red"` | ||
Blue []string `json:"blue"` | ||
} | ||
// This is a comment. | ||
type LockyColors struct { | ||
Red string `json:"red"` | ||
} | ||
// This is a comment. | ||
type CowyColors struct { | ||
Lifetime string `json:"lifetime"` | ||
} | ||
// This is a comment. | ||
type BoxyColorsTypes string | ||
const ( | ||
BoxyColorsTypeVariantRed BoxyColorsTypes = "Red" | ||
BoxyColorsTypeVariantBlue BoxyColorsTypes = "Blue" | ||
BoxyColorsTypeVariantGreen BoxyColorsTypes = "Green" | ||
) | ||
type BoxyColors struct{ | ||
Type BoxyColorsTypes `json:"type"` | ||
content interface{} | ||
} | ||
|
||
func (b *BoxyColors) UnmarshalJSON(data []byte) error { | ||
var enum struct { | ||
Tag BoxyColorsTypes `json:"type"` | ||
Content json.RawMessage `json:"content"` | ||
} | ||
if err := json.Unmarshal(data, &enum); err != nil { | ||
return err | ||
} | ||
|
||
b.Type = enum.Tag | ||
switch b.Type { | ||
case BoxyColorsTypeVariantRed: | ||
return nil | ||
case BoxyColorsTypeVariantBlue: | ||
return nil | ||
case BoxyColorsTypeVariantGreen: | ||
var res string | ||
b.content = &res | ||
|
||
} | ||
if err := json.Unmarshal(enum.Content, &b.content); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (b BoxyColors) MarshalJSON() ([]byte, error) { | ||
var enum struct { | ||
Tag BoxyColorsTypes `json:"type"` | ||
Content interface{} `json:"content,omitempty"` | ||
} | ||
enum.Tag = b.Type | ||
enum.Content = b.content | ||
return json.Marshal(enum) | ||
} | ||
|
||
func (b BoxyColors) Green() string { | ||
res, _ := b.content.(*string) | ||
return *res | ||
} | ||
|
||
func NewBoxyColorsTypeVariantRed() BoxyColors { | ||
return BoxyColors{ | ||
Type: BoxyColorsTypeVariantRed, | ||
} | ||
} | ||
func NewBoxyColorsTypeVariantBlue() BoxyColors { | ||
return BoxyColors{ | ||
Type: BoxyColorsTypeVariantBlue, | ||
} | ||
} | ||
func NewBoxyColorsTypeVariantGreen(content string) BoxyColors { | ||
return BoxyColors{ | ||
Type: BoxyColorsTypeVariantGreen, | ||
content: &content, | ||
} | ||
} | ||
|
Oops, something went wrong.