Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement generic bounds translation into Go #222

Open
AndyTitu opened this issue Dec 30, 2024 · 0 comments
Open

Implement generic bounds translation into Go #222

AndyTitu opened this issue Dec 30, 2024 · 0 comments

Comments

@AndyTitu
Copy link
Contributor

AndyTitu commented Dec 30, 2024

📰 Overview

Since PR: #221, typeshare correctly translates struct generics in Go.
The following Rust snippet:

#[typeshare]
pub(crate) struct ItemsGetAllResponse {
    pub(crate) individual_responses: Vec<Response<Item, Error>>,
}

#[typeshare]
pub(crate) struct Response<T, E> {
    pub(crate) content: Option<T>,
    pub(crate) error: Option<E>,
}

Correctly translates to:

type Response[T any, E any] struct {
	Content *T `json:"content,omitempty"`
	Error *E `json:"error,omitempty"`
}

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

However, generic bounds aren't supported:

#[typeshare]
pub(crate) struct IndividualResponse<T: Item, E: Error> {
    pub(crate) content: Option<T>,
    pub(crate) error: Option<E>,
}

doesn't translate to

type Response[T Item, E Error] struct {
	Content *T `json:"content,omitempty"`
	Error *E `json:"error,omitempty"`
}
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

No branches or pull requests

1 participant