Unverified Commit c5a437e9 authored by Mark Hammond's avatar Mark Hammond Committed by GitHub
Browse files

CustomTypes are no longer turned into ExternalTypes (#2385)

The bindings all work when the Type::Custom has a different module_path
and external bindings will need to do the same.

Fixes #2025
parent 49e42cdf
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,10 @@ or use UDL with types from more than one crate.


- Added the `FfiType::MutReference` variant.
- Added the `FfiType::MutReference` variant.


- `Type::Custom` is no longer turned in to a `Type::External` for the bindings. Binding authors
  must check the type is local themselves before deciding to treat it as a local or external type.
  We expect `Type::External` will be removed soon and all types will be treated in this way.

[All changes in [[UnreleasedUniFFIVersion]]](https://github.com/mozilla/uniffi-rs/compare/v0.28.3...HEAD).
[All changes in [[UnreleasedUniFFIVersion]]](https://github.com/mozilla/uniffi-rs/compare/v0.28.3...HEAD).


## v0.28.3 (backend crates: v0.28.3) - (_2024-11-08_)
## v0.28.3 (backend crates: v0.28.3) - (_2024-11-08_)
+9 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,15 @@ pub fn get_ouid(ouid: Option<Ouid>) -> Ouid {
    ouid.unwrap_or_else(|| Ouid("Ouid".to_string()))
    ouid.unwrap_or_else(|| Ouid("Ouid".to_string()))
}
}


// A custom-type wrapping a simple ffitype which is also consumed as an external type (#2025)
pub struct HandleU8(pub u8);
uniffi::custom_newtype!(HandleU8, u8);

#[uniffi::export]
pub fn get_handle_u8(h: Option<HandleU8>) -> HandleU8 {
    h.unwrap_or(HandleU8(2))
}

pub struct GuidHelper {
pub struct GuidHelper {
    pub guid: Guid,
    pub guid: Guid,
    pub guids: Vec<Guid>,
    pub guids: Vec<Guid>,
+1 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ class TestGuid(unittest.TestCase):
        self.assertEqual(test_callback.saw_guid, "callback-test-payload")
        self.assertEqual(test_callback.saw_guid, "callback-test-payload")


    def test_custom(self):
    def test_custom(self):
        self.assertEqual(get_handle_u8(None), 2)
        get_nested_object(InnerObject())
        get_nested_object(InnerObject())


if __name__=='__main__':
if __name__=='__main__':
+6 −1
Original line number Original line Diff line number Diff line
use custom_types::Handle;
use custom_types::Handle;
use ext_types_custom::{ANestedGuid, Guid, Ouid};
use ext_types_custom::{ANestedGuid, Guid, HandleU8, Ouid};
use ext_types_external_crate::{
use ext_types_external_crate::{
    ExternalCrateDictionary, ExternalCrateInterface, ExternalCrateNonExhaustiveEnum,
    ExternalCrateDictionary, ExternalCrateInterface, ExternalCrateNonExhaustiveEnum,
};
};
@@ -110,6 +110,11 @@ fn get_imported_ouid(ouid: Ouid) -> Ouid {
    ouid
    ouid
}
}


#[uniffi::export]
fn get_imported_handle_u8(h: Option<HandleU8>) -> HandleU8 {
    h.unwrap_or(HandleU8(3))
}

// external custom types wrapping external custom types.
// external custom types wrapping external custom types.
#[uniffi::export]
#[uniffi::export]
fn get_imported_nested_guid(guid: Option<ANestedGuid>) -> ANestedGuid {
fn get_imported_nested_guid(guid: Option<ANestedGuid>) -> ANestedGuid {
+1 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ assert(getGuid("guid") == "guid")
assert(getOuid("ouid") == "ouid")
assert(getOuid("ouid") == "ouid")
//assert(getImportedGuid("guid") == "guid")
//assert(getImportedGuid("guid") == "guid")
assert(getImportedOuid("ouid") == "ouid")
assert(getImportedOuid("ouid") == "ouid")
assert(getImportedHandleU8(null) == 3u.toUByte())


val uot = UniffiOneType("hello")
val uot = UniffiOneType("hello")
assert(getUniffiOneType(uot) == uot)
assert(getUniffiOneType(uot) == uot)
Loading