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

Enum custom type example #1139

Open
bendk opened this issue Dec 9, 2021 · 2 comments
Open

Enum custom type example #1139

bendk opened this issue Dec 9, 2021 · 2 comments

Comments

@bendk
Copy link
Contributor

bendk commented Dec 9, 2021

Right now all our custom type examples are structs. It could be good to add some Enum examples -- e.g. a JSONObject as a JSONEnum which translates to a serde_json::Value.

There are two issues with serde_json::Value though:

  • It's a recursive enum, so we would need to implement Add support for recursive enums #396.
  • On Kotlin, I don't think there's a builtin Json type, and we don't want the examples to depend on 3rd party libraries

So we should either resolve those issues, or think of a different Enum example.

┆Issue is synchronized with this Jira Task
┆friendlyId: UNIFFI-125

@mhammond
Copy link
Member

I vaguely think JSON isn't a great example here, as I don't think a custom enum would make sense in practice - ie, it might mislead people into thinking that exposing JSON via a custom enum is the "correct" approach to a custom JSON type.

Maybe an Any enum?

[Enum]
interface Any {
  I32(i32),
  String(string),

It doesn't have to be thorough, just enough to demonstrate the idea?

@mhammond
Copy link
Member

(hrm - I didn't think that through really - the point is not to define the enum in the udl, right? But maybe there's a skerrick of an idea there?)

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

2 participants