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

Dart Guest Initial Impl #99

Closed
wants to merge 2 commits into from
Closed

Dart Guest Initial Impl #99

wants to merge 2 commits into from

Conversation

helpisdev
Copy link

This PR adds an initial implementation of how a Dart guest could look like.

It is largely based on the Typescript guest, with minor modifications/adjustments for Dart.

Currently all the .wit examples compile, except for the union one, since Dart does not support unions. Likewise, the variant.wit file will not compile as it contains a union definition, but if that changes to let's say a type definition, then it will work as expected.

Lastly, to support a few features (e.g. tuples), Dart 3.0.0 has been used, which still in development mode. In the coming weeks the beta version will be released, and by mid-summer 2023 it will reach a stable version. Since the nature of this package is still experimental, I don't believe this is much of a problem, since by the time this package has matured, so will have Dart 3.

@netlify
Copy link

netlify bot commented Apr 6, 2023

Deploy Preview for tauri-bindgen canceled.

Name Link
🔨 Latest commit dd24f51
🔍 Latest deploy log https://app.netlify.com/sites/tauri-bindgen/deploys/642eb59a35c5520008ac2dac

@JonasKruckenberg
Copy link
Contributor

Very cool I'll give it a proper look tomorrow!

Re the union issue: What would possible workarounds look like? For example the guest-ts generator currently outputs a workaround using interfaces and a union to represent the variant type. Can we do something similar for dart here?

@helpisdev
Copy link
Author

To my knowledge, there are no easy workarounds. One option would be to use the freezed package, but it might be an overkill since it does more than our use case.

A naive/simple implementation would look like the current variant type implementation, playing around with subclasses and factory constructors, but I don't feel it solves the issue that much.

When I was transforming the TS api to dart, wherever there were union type definitions, I usually worked around them using enums or by making specialized Union classes with type parameters. This worked well for simple "one or the other" cases, with a simple Union class abstraction with a left and right constructors, but I don't know how it would scale for larger unions. That Union implementation is almost identical to the implementation I provided for an equivalent Result type for Dart.

Workarounds are surely possible, but might be unintuitive or cumbersome, and most of the times would delegate the type checking to runtime, not gaining much from code generation that way, other than automation. It is something that should be investigated further, but I wouldn't devote to it much time yet, since it is a highly requested language feature and it might be implemented by the core dart team sooner or later.

@helpis-software helpis-software closed this by deleting the head repository May 18, 2023
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.

3 participants