feat: [wip] add support for uniffi-rs foreign bindings #482
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Motivation for this PR is allowing
UInt
s to be lowered & lifted to foreign bindings (e.g. Swift & Kotlin) through Mozilla's https://github.com/mozilla/uniffi-rs. Rust libraries relying on uniffi, would be able to work withUInt
s in foreign code. For us, we would rely on this for https://github.com/worldcoin/walletkit & https://github.com/worldcoin/bedrockSolution
There are two conceptual solutions.
UInt
s to foreign code. A U256 for example would be lowered as a struct with 4xu64
, not to dissimilar to the mainUInt
type. This is the most Rust-compatible, no changes are needed on the Rust side for downstream crates. The trade-off is that on the foreign side, no methods can be exposed for the type. Everything would have to be exposed as first-level functions (and potentially patched on the foreign side with extensions).UInt
which can be extended to expose additional functionality to foreign code (see 4ee8e1c#diff-335af168ef5906f688caca114e10649fb5ccb74611bce562a82533c4324cb043). Trade-off is it'll require conversions in the Rust side.In any case, uniffi does not support exposing generics (the
BITS
/LIMBS
), so explicit declarations for aliases will have to be used. An alternative approach would be introducing a new type, but I don't think that's the best approach.PR Checklist