thlorenz / rid

Rust integrated Dart framework providing an easy way to build Flutter apps with Rust.
63 stars 4 forks source link

refactor: simplifying `Raw*` type renamings #8

Closed thlorenz closed 3 years ago

thlorenz commented 3 years ago

In order to indicate to the user that using raw types directly is a bit dangerous as memory safety cannot be guaranteed, they are prefixed with Raw*. Previously this was done for the generated rust code as well via typedefs. However this lead to overly complicated generation code and issues, i.e. duplicate typedefs in the same scope.

This change simplifies this by performing prefixing on the Dart side only. ffigen configs include a section to instruct it to do this for specific structs. For now this was added to the examples, but configs will be generated shortly (see info about follow up PR below).

The Dart wrapper methods also use the prefixed types where necessary.

To get an idea of how generated code is simplified have a look at the changes to tests.

This will also make it a lot easier to apply future changes, thus after cleaning up the semi-obsolete rid-macro-impl/src/model/parsed_struct.rs implementation I can efficiently tackle other Rust collection types as @chertov requested.

Follow up PR

The user shouldn't have to figure out which structs ffigen should rename and since @MGlolenstine demonstrated how to configure it outside of the pubspec.yaml I'll implement a change to have this config auto generated for the particular platforms. This is as an addendum to this PR (thus they should be merged together and the rid-examples repo updated accordingly when that is done). It is also another step towards a rid cli tool which takes care of project setup and code generation.