Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the 'ext-types/guid' fixture to 'ext-types/custom-types' #2072

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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>"]
Expand All @@ -8,7 +8,7 @@ publish = false

[lib]
crate-type = ["lib", "cdylib"]
name = "ext_types_guid"
name = "ext_types_custom"

[dependencies]
anyhow = "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -96,4 +105,4 @@ impl UniffiCustomTypeConverter for Guid {
}
}

uniffi::include_scaffolding!("guid");
uniffi::include_scaffolding!("custom_types");
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions fixtures/ext-types/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions fixtures/ext-types/lib/src/ext-types-lib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion fixtures/ext-types/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/ext-types/lib/uniffi.toml
Original file line number Diff line number Diff line change
@@ -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 = ""
4 changes: 2 additions & 2 deletions fixtures/ext-types/proc-macro-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -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"}
Expand Down
6 changes: 3 additions & 3 deletions fixtures/ext-types/proc-macro-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
2 changes: 1 addition & 1 deletion fixtures/ext-types/proc-macro-lib/uniffi.toml
Original file line number Diff line number Diff line change
@@ -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 = ""