Comments (9)
Type aliases are complicated in Python and we use strings exactly to avoid the problem with forward references. I don't understand what change you are proposing should be made to uniffi (ie, this seems a problem with Python in general and nothing specific to uniffi?)
from uniffi-rs.
Sorry for not being clear. You said "we use strings exactly to avoid the problem with forward references" but we're getting compilation errors because we're not doing anything like that for aliases today, only for function types. But when I went down the path of dealing with the problem the same way, I ran into the "Variable not allowed in type expression" error.
So I can think of two possible ways to deal with this problem, but was hoping others could come up with something better:
- Implement sorting of type aliases. Ideally it would be able to automatically sort based on references to other types, but an easier solution could be a way to manually indicate ordering.
- Switch to
typing.TypeAlias
. This wouldn't work for pre-3.10 Python, which is why I was asking what the minimum supported version is today.
from uniffi-rs.
We support all currently supported Python versions, which IIRC, is currently 3.8+ (even though CI is currently using 3.11)
I'm afraid I still don't have a good understanding of the problem you are hitting though - would it be possible to demonstrate it by making the smallest possible patch to one of our tests? Eg, test_simple_fns has one test, test_futures has another, but similar tests in any other fixture would be great too. We'd need such a test for any potential fix anyway, so this would help get the ball rolling.
from uniffi-rs.
Sure, I opened a PR here #2068 to demonstrate the error in the proc-macro fixture, but I can move it to a different test if you'd prefer
from uniffi-rs.
That's perfect, thanks!
from uniffi-rs.
In that PR, you are trying to define a "custom type" in terms of another custom type. The custom type docs indicate that they are used to wrap a "builtin" - there's no intention they are able to wrap non-builtin types. In other words, the bug in that PR seems to be that we don't fail with a clear error about the wrapped type.
I'd like to better understand your use-case - in that example, why wouldn't your API just use CustomNewtype
directly? ie, what value does ASecondCustomNewtype
offer?
from uniffi-rs.
I'd like to better understand your use-case
Sure! The example in the test was a minimal reproducible example; I definitely would just use CustomNewtype
in that case.
My use case is mainly around composition of types in dict
s. I have several functions with similar-looking signatures that are actually distinct and like to use newtypes to help distinguish this.
For example, I'd like to do
pub struct FieldId(pub String);
pub struct EncryptedField(pub Vec<u8>);
pub struct EncryptedFields(pub HashMap<FieldId, EncryptedField>);
When I use custom_newtype!
on these 3 structs, it will generate aliases in alphabetical order and EncryptedFields
won't yet know what a FieldId
is.
from uniffi-rs.
In other words, the bug in that PR seems to be that we don't fail with a clear error about the wrapped type.
Welp, I guess I jumped the gun there - we do support any type, not just "builtin" types. In the linked PR I updated the docs and added tests for some of these cases.
from uniffi-rs.
That's fantastic, thanks so much for doing that @mhammond
from uniffi-rs.
Related Issues (20)
- Undefined features `log_panics` and `log_backtraces` HOT 1
- How to implement builder pattern using uniffi? HOT 6
- Uniffi ForeignFuture inconsistenty dropped HOT 10
- Add tracing to FFI calls
- Make it possible to rename structs HOT 9
- ld: building for 'macOS', but linking in object file built for 'iOS' HOT 1
- Change introduced in v0.28.1 breaks cargo-swift HOT 2
- swift: record: drop explicit implementation of Equatable and Hashable?
- Async runtime for function binding defined in UDL file HOT 10
- Prefix FFI callback function and struct names with the crate name
- Export callback interface as a struct property HOT 1
- error calling from Swift: `there is no reactor running, must be called from the context of a Tokio 1.x runtime` HOT 3
- Ability to completely remove logging code (likely with a feature flag) HOT 2
- `unknown throw type` error when composing multiple crate HOT 6
- Cleaner implementation still requiring Android API 33 HOT 2
- Hope the protocol generated by callback_interface in Swift does not include AnyObject
- How to catch an exception on rust side? HOT 1
- Support HUAWEI HarmonyOS system HOT 1
- `error: future cannot be sent between threads safely` when trying to build for `wasm32-unknown-unknown` HOT 1
- Call a function at every ffi point
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uniffi-rs.