Skip to content

Conversation

@AndyTitu
Copy link
Contributor

@AndyTitu AndyTitu commented Dec 30, 2024

📰 Overview

The current TypeShare implementation we're using doesn't support Struct Generics in Go.

🚀 Acceptance Criteria

  • The following rust snippet should translate to the following Go snippet:
#[typeshare]
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ItemsGetAllResponse {
    pub(crate) individual_responses: Vec<IndividualResponse<Item, ItemsGetAllError>>,
}

#[typeshare]
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub(crate) struct IndividualResponse<T, E> {
    pub(crate) content: Option<T>,
    pub(crate) error: Option<E>,
}
type IndividualResponse[T any, E any] struct {
	Content *T `json:"content,omitempty"`
	Error *E `json:"error,omitempty"`
}

type ItemsGetAllResponse struct {
	IndividualResponses []IndividualResponse[Item, ItemsGetAllError] `json:"individualResponses"`
}

while currently it translates to

type IndividualResponse struct {
	Content *T `json:"content,omitempty"`
	Error *E `json:"error,omitempty"`
}

type ItemsGetAllResponse struct {
	IndividualResponses []IndividualResponse<Item, ItemsGetAllError> `json:"individualResponses"`
}

Copy link
Member

@hculea hculea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't functionally tested, but code looks good. Thanks for the callout on generic trait bounds.

@AndyTitu AndyTitu merged commit d8ba388 into 1Password:main Dec 30, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants