-
Notifications
You must be signed in to change notification settings - Fork 267
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
Use a type alias to allow bindings to take advantage of custom types #4412
Use a type alias to allow bindings to take advantage of custom types #4412
Conversation
6d9533c
to
4c7260c
Compare
I primarily want this for the react-native-matrix-sdk (Typescript), but I believe it is possible to add custom unpackers to Kotlin/Swift as well. That would of course be a breaking API change for any users of this library, the current iteration of this should fallback to u64 automatically. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4412 +/- ##
==========================================
- Coverage 85.27% 85.27% -0.01%
==========================================
Files 282 282
Lines 31186 31186
==========================================
- Hits 26594 26593 -1
- Misses 4592 4593 +1 ☔ View full report in Codecov by Sentry. |
Small nitpick about the PR description, it talks about a marker trait but there is no new trait involved here, I think you meant "newtype"? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a nice improvement! I'm suggesting a renaming but everything else is nice!
4c7260c
to
69811df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review comments were addressed and the PR seems fine to me as well.
This PR adds a new type alias to the matrix-sdk-ffi crate called Date64. This is aliased to u64 for backwards compatibility (so no change to Swift/Kotlin as is), but as a distinct type it will allow uniffi integrations to customize the unpacking of the type automatically: https://mozilla.github.io/uniffi-rs/latest/udl/custom_types.html
Using this, it is possible to make the uniffi layer automatically convert these from u64 -> an appropriate system Date class in the generated code layer.
Today a
u64
type can mean either a count or a date, so without an alias implementing a customType would not be possible. At the very least, the type helps improve the documentation, even if individual bindings choose not to adopt this in their UDL configs.Signed-off-by: Daniel Salinas