-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a new custom type system described in the new docs. This system is easier to use and also allows us to do some extra tricks behind the scene. For example, I hope to add a flag that will toggle between implementing `FfiConverter` for the local tag vs a blanket impl. It's not possible to do that with the current system and adding support would be awkward. I wanted to keep backwards compatibility for a bit, but couldn't figure out a good way to do it. The main issue is that for the old system, if a custom type is declared in the UDL then we generate the `FfiConverter` implementation, while the new system expects the user to call `custom_type!` to create the impl. I tried to get things working by creating a blanket impl of `FfiConverter` for types that implemented `UniffiCustomTypeConverter`, but ran into issues -- the first blocker I found was that there's no way to generate `TYPE_ID_META` since we don't know the name of the custom type. Removed the nested-module-import fixture. The custom type code will no longer test it once we remove the old code, since it's not using `UniffiCustomTypeConverter`. I couldn't think of a way to make it work again.
- Loading branch information
Showing
23 changed files
with
490 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# v0.28.x -> v0.29.x | ||
|
||
## Custom types | ||
|
||
Custom types are now implemented using a macro, rather than implementing the `UniffiCustomTypeConverter` trait. | ||
We did this to help fix some edge-cases with custom types wrapping types from other crates (eg, Url). | ||
|
||
Before: | ||
|
||
```rust | ||
impl UniffiCustomTypeConverter for NewCustomType { | ||
type Builtin = BridgeType; | ||
|
||
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> { | ||
... | ||
} | ||
|
||
fn from_custom(obj: Self) -> Self::Builtin { | ||
... | ||
} | ||
} | ||
``` | ||
|
||
After: | ||
|
||
``` | ||
uniffi::custom_type!(NewCustomType, BridgeType, { | ||
try_lift: |val| { Ok(...) }, | ||
lower: |obj| { ... }, | ||
}) | ||
``` | ||
|
||
Changes: | ||
|
||
* The term "bridge type" replaces "builtin type". The reason for this is that this type does not actually need to be a builtin type. | ||
* `into_custom/from_custom` are now named `try_lift/lower`. This simplifies/improves the docs, | ||
since we can leverage the existing concepts of lifting/lowering rather than introduce a new | ||
converter concept. | ||
* Records, Enums, and Objects are also supported. | ||
* The `custom_type!` macro is more flexible than the old system. | ||
For example, the `try_lift` and `lower` can be omitted in many cases. | ||
If `lower` is omitted, then `Into<BridgeType>` will be used instead. | ||
If `try_lift` is omitted, then `TryInto<NewCustomType>` will be used instead. | ||
The non-symmetry is slightly awkward, but `TryInto` is better to use than `TryFrom` because of the blanket impls in the standard library and we decided that writing `try_lift` would be more natural for users invoking the macro. | ||
|
||
See the [Custom Types](./udl/custom_types.md) for details and other features of the new macro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.