1Password / typeshare

Typeshare is the ultimate tool for synchronizing your type definitions between Rust and other languages for seamless FFI.
Apache License 2.0
2.4k stars 99 forks source link

Elm support with json Decoders #23

Open kreibaum opened 1 year ago

kreibaum commented 1 year ago

Would I be welcome to work on an Elm Language implementation for typeshare?

Elm is a small language, it has very strict type checking and I like using it together with a rust backend.

One peculiarity is, that you can't just tell Elm "here is some data, trust me it is a MyCustomType". Instead you need to also generate Encoders and Decoders that describe how the json is created / parsed.

Would that also be something you see in typeshare? So far I have just read through parts of the typescript language definition and looked at the Language type. Neither really has a section where I would put it. But it might make sense to put an encoder and a decoder right after each type.

Edit, to give some time information: I don't expect to work on this before new year (2023).

kreibaum commented 1 year ago

As an example, here is a rust class

https://github.com/kreibaum/rust_elm_typegen/blob/main/src/tests/person.rs

And when translated to Elm you get

https://github.com/kreibaum/rust_elm_typegen/blob/main/src/tests/Person.elm

Note that in Rust, everything except for the person struct is just in there to test that the typegen utility doesn't just pick up everything.

snowsignal commented 1 year ago

We would absolutely be open to adding support for Elm. Feel free to open a PR!

Would that also be something you see in typeshare? So far I have just read through parts of the typescript language definition and looked at the Language type. Neither really has a section where I would put it. But it might make sense to put an encoder and a decoder right after each type.

We do define custom encoders and decoders in some cases - take a look at our Swift implementation for an example of this: https://github.com/1Password/typeshare/blob/main/core/data/tests/can_generate_generic_struct/output.swift#L46.

snowsignal commented 1 year ago

I should clarify that the low-priority tag means the Typeshare team won't be actively working on this issue, at least for the moment. But you are absolutely free to open a PR.

kreibaum commented 1 year ago

That is precisely my expectation. But thanks for clarifying.

Feel free to also close this issue if you want to fight backlog growth and then I'll just open another one once I am actually working on something.