thlorenz / rid

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

feat/vec export #13

Closed thlorenz closed 3 years ago

thlorenz commented 3 years ago

Summary

This PR adds support for more return types for function exports via #[rid::export]. It contains some WIP for HashMap support as well. While working on that I realized that in order to send the keys() as a Vec it needs to be supported first.

Supported Types

I added lots of tests which verify that the following export return types are now supported:

Vecs

Vec<&struct>
Vec<&primitive>
Vec<&String>
Vec<&CString>
Vec<&str>

In the case of vecs with a string-like type the string value is not resolved until the item in the Vec is accessed in order to push out copying the data to convert to a *const char until the last possible moment.

Primitives

// owned
u8, i8, u16, i16 .. u64, i64
bool

// refererences
&u8, &i8, &u16, &i16 .. &u64, &i64
&bool

Strings

String, CString
&String, &CString, &str

They are sent as *const char to Dart.

C-Style Enums

Enums are converted to i8 when sent to Dart and serialized back into an enum on the Dart end.

Commits