зеркало из https://github.com/mozilla/uniffi-rs.git
Rename the 'ext-types/guid' fixture to 'ext-types/custom-types' (#2072)
This commit is contained in:
Родитель
1007f00e8c
Коммит
15a347327a
|
@ -1680,19 +1680,15 @@ dependencies = [
|
|||
"bytes",
|
||||
"uniffi",
|
||||
"uniffi-example-custom-types",
|
||||
"uniffi-fixture-ext-types-custom-types",
|
||||
"uniffi-fixture-ext-types-external-crate",
|
||||
"uniffi-fixture-ext-types-guid",
|
||||
"uniffi-fixture-ext-types-lib-one",
|
||||
"uniffi-fixture-ext-types-sub-lib",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uniffi-fixture-ext-types-external-crate"
|
||||
version = "0.22.0"
|
||||
|
||||
[[package]]
|
||||
name = "uniffi-fixture-ext-types-guid"
|
||||
name = "uniffi-fixture-ext-types-custom-types"
|
||||
version = "0.22.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
|
@ -1701,6 +1697,10 @@ dependencies = [
|
|||
"uniffi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uniffi-fixture-ext-types-external-crate"
|
||||
version = "0.22.0"
|
||||
|
||||
[[package]]
|
||||
name = "uniffi-fixture-ext-types-http-headermap"
|
||||
version = "0.22.0"
|
||||
|
@ -1729,7 +1729,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"uniffi",
|
||||
"uniffi-example-custom-types",
|
||||
"uniffi-fixture-ext-types-guid",
|
||||
"uniffi-fixture-ext-types-custom-types",
|
||||
"uniffi-fixture-ext-types-lib-one",
|
||||
"url",
|
||||
]
|
||||
|
|
|
@ -28,7 +28,7 @@ members = [
|
|||
"fixtures/callbacks",
|
||||
"fixtures/error-types",
|
||||
|
||||
"fixtures/ext-types/guid",
|
||||
"fixtures/ext-types/custom-types",
|
||||
"fixtures/ext-types/http-headermap",
|
||||
"fixtures/ext-types/uniffi-one",
|
||||
"fixtures/ext-types/lib",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "uniffi-fixture-ext-types-guid"
|
||||
name = "uniffi-fixture-ext-types-custom-types"
|
||||
edition = "2021"
|
||||
version = "0.22.0"
|
||||
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
|
||||
|
@ -8,7 +8,7 @@ publish = false
|
|||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "ext_types_guid"
|
||||
name = "ext_types_custom"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
|
@ -3,5 +3,5 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
fn main() {
|
||||
uniffi::generate_scaffolding("src/guid.udl").unwrap();
|
||||
uniffi::generate_scaffolding("src/custom_types.udl").unwrap();
|
||||
}
|
|
@ -16,7 +16,7 @@ callback interface GuidCallback {
|
|||
Guid run(Guid arg);
|
||||
};
|
||||
|
||||
namespace ext_types_guid {
|
||||
namespace ext_types_custom {
|
||||
// Note this intentionally does not throw an error - uniffi will panic if
|
||||
// a Guid can't be converted.
|
||||
Guid get_guid(optional Guid? value);
|
|
@ -1,6 +1,10 @@
|
|||
// A trivial guid.
|
||||
// A trivial guid, declared as `[Custom]` in the UDL.
|
||||
pub struct Guid(pub String);
|
||||
|
||||
// Ditto, using a proc-macro.
|
||||
pub struct Ouid(pub String);
|
||||
uniffi::custom_newtype!(Ouid, String);
|
||||
|
||||
// This error is represented in the UDL.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum GuidError {
|
||||
|
@ -46,6 +50,11 @@ fn try_get_guid(guid: Option<Guid>) -> std::result::Result<Guid, GuidError> {
|
|||
})
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
pub fn get_ouid(ouid: Option<Ouid>) -> Ouid {
|
||||
ouid.unwrap_or_else(|| Ouid("Ouid".to_string()))
|
||||
}
|
||||
|
||||
pub struct GuidHelper {
|
||||
pub guid: Guid,
|
||||
pub guids: Vec<Guid>,
|
||||
|
@ -96,4 +105,4 @@ impl UniffiCustomTypeConverter for Guid {
|
|||
}
|
||||
}
|
||||
|
||||
uniffi::include_scaffolding!("guid");
|
||||
uniffi::include_scaffolding!("custom_types");
|
|
@ -3,7 +3,7 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import unittest
|
||||
from ext_types_guid import *
|
||||
from ext_types_custom import *
|
||||
|
||||
class TestCallback(GuidCallback):
|
||||
def run(self, guid):
|
||||
|
@ -14,6 +14,7 @@ class TestGuid(unittest.TestCase):
|
|||
def test_get_guid(self):
|
||||
self.assertEqual(get_guid(None), "NewGuid")
|
||||
self.assertEqual(get_guid("SomeGuid"), "SomeGuid")
|
||||
self.assertEqual(get_ouid(None), "Ouid")
|
||||
|
||||
def test_guid_helper(self):
|
||||
helper = get_guid_helper(None)
|
|
@ -8,7 +8,7 @@ publish = false
|
|||
|
||||
[package.metadata.uniffi.testing]
|
||||
external-crates = [
|
||||
"uniffi-fixture-ext-types-guid",
|
||||
"uniffi-fixture-ext-types-custom-types",
|
||||
"uniffi-fixture-ext-types-lib-one",
|
||||
"uniffi-fixture-ext-types-external-crate",
|
||||
"uniffi-fixture-ext-types-sub-lib",
|
||||
|
@ -26,7 +26,7 @@ uniffi = { workspace = true }
|
|||
|
||||
uniffi-fixture-ext-types-external-crate = {path = "../external-crate"}
|
||||
uniffi-fixture-ext-types-lib-one = {path = "../uniffi-one"}
|
||||
uniffi-fixture-ext-types-guid = {path = "../guid"}
|
||||
uniffi-fixture-ext-types-custom-types = {path = "../custom-types"}
|
||||
uniffi-fixture-ext-types-sub-lib = {path = "../sub-lib"}
|
||||
|
||||
# Reuse one of our examples.
|
||||
|
|
|
@ -43,10 +43,9 @@ typedef extern UniffiOneUDLTrait;
|
|||
[ExternalExport="uniffi_one"]
|
||||
typedef extern UniffiOneProcMacroType;
|
||||
|
||||
// A "wrapped" type defined in the guid crate (ie, defined in `../../guid/src/lib.rs` and
|
||||
// "declared" in `../../guid/src/guid.udl`). But it's still "external" from our POV,
|
||||
// So same as the `.udl` type above!
|
||||
[External="ext_types_guid"]
|
||||
// A Custom (ie, "wrapped") type defined externally in `../../custom-types/src/lib.rs`,
|
||||
// but because it's in a UDL it's still "external" from our POV, so same as the `.udl` type above.
|
||||
[External="ext_types_custom"]
|
||||
typedef extern Guid;
|
||||
|
||||
// And re-use the `custom-types` example - this exposes `Url` and `Handle`
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use custom_types::Handle;
|
||||
use ext_types_custom::Guid;
|
||||
use ext_types_external_crate::{
|
||||
ExternalCrateDictionary, ExternalCrateInterface, ExternalCrateNonExhaustiveEnum,
|
||||
};
|
||||
use ext_types_guid::Guid;
|
||||
use std::sync::Arc;
|
||||
use uniffi_one::{
|
||||
UniffiOneEnum, UniffiOneInterface, UniffiOneProcMacroType, UniffiOneTrait, UniffiOneType,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[bindings.python.external_packages]
|
||||
# This fixture does not create a Python package, so we want all modules to be top-level modules.
|
||||
custom_types = ""
|
||||
ext_types_guid = ""
|
||||
ext_types_custom = ""
|
||||
uniffi_one_ns = ""
|
||||
imported_types_sublib = ""
|
||||
|
|
|
@ -8,7 +8,7 @@ publish = false
|
|||
|
||||
[package.metadata.uniffi.testing]
|
||||
external-crates = [
|
||||
"uniffi-fixture-ext-types-guid",
|
||||
"uniffi-fixture-ext-types-custom-types",
|
||||
"uniffi-fixture-ext-types-lib-one",
|
||||
"uniffi-example-custom-types",
|
||||
]
|
||||
|
@ -23,7 +23,7 @@ bytes = "1.3"
|
|||
uniffi = { workspace = true }
|
||||
|
||||
uniffi-fixture-ext-types-lib-one = {path = "../uniffi-one"}
|
||||
uniffi-fixture-ext-types-guid = {path = "../guid"}
|
||||
uniffi-fixture-ext-types-custom-types = {path = "../custom-types"}
|
||||
|
||||
# Reuse one of our examples.
|
||||
uniffi-example-custom-types = {path = "../../../examples/custom-types"}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use custom_types::Handle;
|
||||
use ext_types_guid::Guid;
|
||||
use ext_types_custom::Guid;
|
||||
use std::sync::Arc;
|
||||
use uniffi_one::{
|
||||
UniffiOneEnum, UniffiOneInterface, UniffiOneProcMacroType, UniffiOneTrait, UniffiOneType,
|
||||
|
@ -9,7 +9,7 @@ use url::Url;
|
|||
uniffi::use_udl_record!(uniffi_one, UniffiOneType);
|
||||
uniffi::use_udl_enum!(uniffi_one, UniffiOneEnum);
|
||||
uniffi::use_udl_object!(uniffi_one, UniffiOneInterface);
|
||||
uniffi::use_udl_record!(ext_types_guid, Guid);
|
||||
uniffi::use_udl_record!(ext_types_custom, Guid);
|
||||
uniffi::use_udl_record!(custom_types, Url);
|
||||
uniffi::use_udl_record!(custom_types, Handle);
|
||||
|
||||
|
@ -219,7 +219,7 @@ fn get_newtype_handle_value(u: NewtypeHandle) -> i64 {
|
|||
|
||||
#[uniffi::export]
|
||||
fn get_guid_procmacro(g: Option<Guid>) -> Guid {
|
||||
ext_types_guid::get_guid(g)
|
||||
ext_types_custom::get_guid(g)
|
||||
}
|
||||
|
||||
uniffi::setup_scaffolding!("imported_types_lib");
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import asyncio
|
||||
import unittest
|
||||
import urllib
|
||||
from ext_types_guid import *
|
||||
from ext_types_custom import *
|
||||
from imported_types_lib import *
|
||||
from uniffi_one_ns import *
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[bindings.python.external_packages]
|
||||
# This fixture does not create a Python package, so we want all modules to be top-level modules.
|
||||
custom_types = ""
|
||||
ext_types_guid = ""
|
||||
ext_types_custom = ""
|
||||
uniffi_one_ns = ""
|
||||
|
|
Загрузка…
Ссылка в новой задаче