From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../uniffi-fixture-callbacks/src/callbacks.udl | 12 +++++++++++ .../components/uniffi-fixture-callbacks/src/lib.rs | 23 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl create mode 100644 toolkit/components/uniffi-fixture-callbacks/src/lib.rs (limited to 'toolkit/components/uniffi-fixture-callbacks/src') 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 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 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, items: Vec) { + 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, items: Vec) { + log_even_numbers(logger, items) +} + +include!(concat!(env!("OUT_DIR"), "/callbacks.uniffi.rs")); -- cgit v1.2.3