summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-fixture-callbacks
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/uniffi-fixture-callbacks
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-fixture-callbacks')
-rw-r--r--toolkit/components/uniffi-fixture-callbacks/Cargo.toml14
-rw-r--r--toolkit/components/uniffi-fixture-callbacks/build.rs7
-rw-r--r--toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl12
-rw-r--r--toolkit/components/uniffi-fixture-callbacks/src/lib.rs23
4 files changed, 56 insertions, 0 deletions
diff --git a/toolkit/components/uniffi-fixture-callbacks/Cargo.toml b/toolkit/components/uniffi-fixture-callbacks/Cargo.toml
new file mode 100644
index 0000000000..19a8d61070
--- /dev/null
+++ b/toolkit/components/uniffi-fixture-callbacks/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "uniffi-fixture-callbacks"
+edition = "2021"
+version = "0.21.0"
+authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
+license = "MPL-2.0"
+publish = false
+
+[dependencies]
+uniffi = { workspace = true }
+thiserror = "1.0"
+
+[build-dependencies]
+uniffi = { workspace = true, features = ["build"] }
diff --git a/toolkit/components/uniffi-fixture-callbacks/build.rs b/toolkit/components/uniffi-fixture-callbacks/build.rs
new file mode 100644
index 0000000000..e7152d922a
--- /dev/null
+++ b/toolkit/components/uniffi-fixture-callbacks/build.rs
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+fn main() {
+ uniffi::generate_scaffolding("./src/callbacks.udl").unwrap();
+}
diff --git a/toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl b/toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl
new file mode 100644
index 0000000000..a6d44ef598
--- /dev/null
+++ b/toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl
@@ -0,0 +1,12 @@
+callback interface Logger {
+ void log(string message);
+ void finished();
+ };
+
+namespace fixture_callbacks {
+ // Log all even numbers in a vec, then call the finished() method
+ void log_even_numbers(Logger logger, sequence<i32> items);
+ // Works exactly the same as `log_even_numbers()`, except we configure this
+ // to run on the main thread in `uniffi-bindgen-gecko-js/config.toml`
+ void log_even_numbers_main_thread(Logger logger, sequence<i32> items);
+};
diff --git a/toolkit/components/uniffi-fixture-callbacks/src/lib.rs b/toolkit/components/uniffi-fixture-callbacks/src/lib.rs
new file mode 100644
index 0000000000..9ada66bca5
--- /dev/null
+++ b/toolkit/components/uniffi-fixture-callbacks/src/lib.rs
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+trait Logger {
+ fn log(&self, message: String);
+ fn finished(&self);
+}
+
+fn log_even_numbers(logger: Box<dyn Logger>, items: Vec<i32>) {
+ for i in items {
+ if i % 2 == 0 {
+ logger.log(format!("Saw even number: {i}"))
+ }
+ }
+ logger.finished();
+}
+
+fn log_even_numbers_main_thread(logger: Box<dyn Logger>, items: Vec<i32>) {
+ log_even_numbers(logger, items)
+}
+
+include!(concat!(env!("OUT_DIR"), "/callbacks.uniffi.rs"));