From 2c3e269690ae0112bb5b28074e82665e444d87b4 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Sun, 10 Sep 2023 19:23:08 +0200 Subject: [PATCH 1/7] wip --- Cargo.toml | 1 + crates/gen-host/src/lib.rs | 6 +- crates/gen-host/tests/chars.rs | 8 +- crates/gen-host/tests/conventions.rs | 28 ++-- crates/gen-host/tests/empty.rs | 4 +- crates/gen-host/tests/flegs.rs | 18 +-- crates/gen-host/tests/floats.rs | 12 +- crates/gen-host/tests/integers.rs | 48 +++---- crates/gen-host/tests/lists.rs | 70 ++++----- crates/gen-host/tests/many-arguments.rs | 8 +- crates/gen-host/tests/multi-return.rs | 14 +- crates/gen-host/tests/records.rs | 26 ++-- crates/gen-host/tests/resources.rs | 8 +- crates/gen-host/tests/simple-functions.rs | 16 +-- crates/gen-host/tests/simple-lists.rs | 12 +- crates/gen-host/tests/small-anonymous.rs | 6 +- crates/gen-host/tests/strings.rs | 10 +- crates/gen-host/tests/unions.rs | 24 ++-- crates/gen-host/tests/variants.rs | 52 +++---- crates/host/Cargo.toml | 2 +- crates/ipc-router-wip/Cargo.toml | 4 +- crates/ipc-router-wip/src/lib.rs | 166 +++++++++++++--------- examples/greet/src-tauri/Cargo.toml | 2 +- examples/greet/src-tauri/tauri.conf.json | 6 - 24 files changed, 291 insertions(+), 260 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8db5e254..ca9cb1f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ serde = "1.0.188" quote = "1.0.33" proc-macro2 = "1.0.66" syn = "2.0.31" +tauri = { git = "https://github.com/tauri-apps/tauri" } [dependencies] clap.workspace = true diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index ee9a4412..a0c8a066 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -334,7 +334,7 @@ impl Host { router.func_wrap( #mod_name, #func_name, - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, #params| -> ::tauri_bindgen_host::anyhow::Result<#result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, #params| -> ::tauri_bindgen_host::anyhow::Result<#result> { let ctx = get_cx(ctx.data()); Ok(ctx.#func_ident(#(#param_idents),*)) @@ -344,8 +344,8 @@ impl Host { }); quote! { - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where diff --git a/crates/gen-host/tests/chars.rs b/crates/gen-host/tests/chars.rs index 5ba05e85..5f9a0d36 100644 --- a/crates/gen-host/tests/chars.rs +++ b/crates/gen-host/tests/chars.rs @@ -9,8 +9,8 @@ pub mod chars { ///A function that returns a character fn return_char(&self) -> char; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod chars { "chars", "take_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: char, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod chars { "chars", "return_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.return_char()) diff --git a/crates/gen-host/tests/conventions.rs b/crates/gen-host/tests/conventions.rs index 93df9f72..da1f2e7e 100644 --- a/crates/gen-host/tests/conventions.rs +++ b/crates/gen-host/tests/conventions.rs @@ -23,8 +23,8 @@ pub mod conventions { fn explicit_snake(&self); fn bool(&self); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -37,7 +37,7 @@ pub mod conventions { "conventions", "kebab_case", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.kebab_case()) @@ -49,7 +49,7 @@ pub mod conventions { "conventions", "foo", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: LudicrousSpeed, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -62,7 +62,7 @@ pub mod conventions { "conventions", "function_with_underscores", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_underscores()) @@ -74,7 +74,7 @@ pub mod conventions { "conventions", "function_with_no_weird_characters", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_no_weird_characters()) @@ -86,7 +86,7 @@ pub mod conventions { "conventions", "apple", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple()) @@ -98,7 +98,7 @@ pub mod conventions { "conventions", "apple_pear", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear()) @@ -110,7 +110,7 @@ pub mod conventions { "conventions", "apple_pear_grape", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear_grape()) @@ -122,7 +122,7 @@ pub mod conventions { "conventions", "a0", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.a0()) @@ -134,7 +134,7 @@ pub mod conventions { "conventions", "is_xml", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.is_xml()) @@ -146,7 +146,7 @@ pub mod conventions { "conventions", "explicit", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.explicit()) @@ -158,7 +158,7 @@ pub mod conventions { "conventions", "explicit_snake", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.explicit_snake()) @@ -170,7 +170,7 @@ pub mod conventions { "conventions", "bool", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.bool()) diff --git a/crates/gen-host/tests/empty.rs b/crates/gen-host/tests/empty.rs index f21f546e..d1447513 100644 --- a/crates/gen-host/tests/empty.rs +++ b/crates/gen-host/tests/empty.rs @@ -4,8 +4,8 @@ pub mod empty { use ::tauri_bindgen_host::serde; use ::tauri_bindgen_host::bitflags; pub trait Empty: Sized {} - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where diff --git a/crates/gen-host/tests/flegs.rs b/crates/gen-host/tests/flegs.rs index 3a1d37d9..510eab8f 100644 --- a/crates/gen-host/tests/flegs.rs +++ b/crates/gen-host/tests/flegs.rs @@ -67,8 +67,8 @@ pub mod flegs { fn roundtrip_flag32(&self, x: Flag32) -> Flag32; fn roundtrip_flag64(&self, x: Flag64) -> Flag64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -81,7 +81,7 @@ pub mod flegs { "flegs", "roundtrip_flag1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag1, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -94,7 +94,7 @@ pub mod flegs { "flegs", "roundtrip_flag2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag2, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -107,7 +107,7 @@ pub mod flegs { "flegs", "roundtrip_flag4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag4, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -120,7 +120,7 @@ pub mod flegs { "flegs", "roundtrip_flag8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag8, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -133,7 +133,7 @@ pub mod flegs { "flegs", "roundtrip_flag16", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag16, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -146,7 +146,7 @@ pub mod flegs { "flegs", "roundtrip_flag32", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -159,7 +159,7 @@ pub mod flegs { "flegs", "roundtrip_flag64", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag64, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/floats.rs b/crates/gen-host/tests/floats.rs index b64c552e..2434a022 100644 --- a/crates/gen-host/tests/floats.rs +++ b/crates/gen-host/tests/floats.rs @@ -9,8 +9,8 @@ pub mod floats { fn float32_result(&self) -> f32; fn float64_result(&self) -> f64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod floats { "floats", "float32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: f32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod floats { "floats", "float64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: f64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -49,7 +49,7 @@ pub mod floats { "floats", "float32_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.float32_result()) @@ -61,7 +61,7 @@ pub mod floats { "floats", "float64_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.float64_result()) diff --git a/crates/gen-host/tests/integers.rs b/crates/gen-host/tests/integers.rs index 1e2104df..07c6d598 100644 --- a/crates/gen-host/tests/integers.rs +++ b/crates/gen-host/tests/integers.rs @@ -39,8 +39,8 @@ pub mod integers { fn r10(&self) -> i128; fn pair_ret(&self) -> (i64, u8); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -53,7 +53,7 @@ pub mod integers { "integers", "a1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u8, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -66,7 +66,7 @@ pub mod integers { "integers", "a2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i8, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -79,7 +79,7 @@ pub mod integers { "integers", "a3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u16, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -92,7 +92,7 @@ pub mod integers { "integers", "a4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i16, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -105,7 +105,7 @@ pub mod integers { "integers", "a5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -118,7 +118,7 @@ pub mod integers { "integers", "a6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -131,7 +131,7 @@ pub mod integers { "integers", "a7", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -144,7 +144,7 @@ pub mod integers { "integers", "a8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -157,7 +157,7 @@ pub mod integers { "integers", "a9", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u128, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -170,7 +170,7 @@ pub mod integers { "integers", "a10", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i128, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -183,7 +183,7 @@ pub mod integers { "integers", "a11", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p1: u8, p2: i8, p3: u16, @@ -205,7 +205,7 @@ pub mod integers { "integers", "r1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r1()) @@ -217,7 +217,7 @@ pub mod integers { "integers", "r2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r2()) @@ -229,7 +229,7 @@ pub mod integers { "integers", "r3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r3()) @@ -241,7 +241,7 @@ pub mod integers { "integers", "r4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r4()) @@ -253,7 +253,7 @@ pub mod integers { "integers", "r5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r5()) @@ -265,7 +265,7 @@ pub mod integers { "integers", "r6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r6()) @@ -277,7 +277,7 @@ pub mod integers { "integers", "r7", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r7()) @@ -289,7 +289,7 @@ pub mod integers { "integers", "r8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r8()) @@ -301,7 +301,7 @@ pub mod integers { "integers", "r9", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r9()) @@ -313,7 +313,7 @@ pub mod integers { "integers", "r10", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r10()) @@ -325,7 +325,7 @@ pub mod integers { "integers", "pair_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(i64, u8)> { let ctx = get_cx(ctx.data()); Ok(ctx.pair_ret()) diff --git a/crates/gen-host/tests/lists.rs b/crates/gen-host/tests/lists.rs index 6530779c..3efc0797 100644 --- a/crates/gen-host/tests/lists.rs +++ b/crates/gen-host/tests/lists.rs @@ -77,8 +77,8 @@ pub mod lists { fn variant_list(&self, x: Vec) -> Vec; fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -91,7 +91,7 @@ pub mod lists { "lists", "list_u8_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -104,7 +104,7 @@ pub mod lists { "lists", "list_u16_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -117,7 +117,7 @@ pub mod lists { "lists", "list_u32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -130,7 +130,7 @@ pub mod lists { "lists", "list_u64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -143,7 +143,7 @@ pub mod lists { "lists", "list_u128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -156,7 +156,7 @@ pub mod lists { "lists", "list_s8_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -169,7 +169,7 @@ pub mod lists { "lists", "list_s16_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -182,7 +182,7 @@ pub mod lists { "lists", "list_s32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -195,7 +195,7 @@ pub mod lists { "lists", "list_s64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -208,7 +208,7 @@ pub mod lists { "lists", "list_s128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -221,7 +221,7 @@ pub mod lists { "lists", "list_float32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -234,7 +234,7 @@ pub mod lists { "lists", "list_float64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -247,7 +247,7 @@ pub mod lists { "lists", "list_u8_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u8_ret()) @@ -259,7 +259,7 @@ pub mod lists { "lists", "list_u16_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u16_ret()) @@ -271,7 +271,7 @@ pub mod lists { "lists", "list_u32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u32_ret()) @@ -283,7 +283,7 @@ pub mod lists { "lists", "list_u64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u64_ret()) @@ -295,7 +295,7 @@ pub mod lists { "lists", "list_u128_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u128_ret()) @@ -307,7 +307,7 @@ pub mod lists { "lists", "list_s8_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s8_ret()) @@ -319,7 +319,7 @@ pub mod lists { "lists", "list_s16_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s16_ret()) @@ -331,7 +331,7 @@ pub mod lists { "lists", "list_s32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s32_ret()) @@ -343,7 +343,7 @@ pub mod lists { "lists", "list_s64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s64_ret()) @@ -355,7 +355,7 @@ pub mod lists { "lists", "list_s128_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s128_ret()) @@ -367,7 +367,7 @@ pub mod lists { "lists", "list_float32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_float32_ret()) @@ -379,7 +379,7 @@ pub mod lists { "lists", "list_float64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_float64_ret()) @@ -391,7 +391,7 @@ pub mod lists { "lists", "tuple_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec<(u8, i8)>, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -404,7 +404,7 @@ pub mod lists { "lists", "string_list_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -417,7 +417,7 @@ pub mod lists { "lists", "string_list_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.string_list_ret()) @@ -429,7 +429,7 @@ pub mod lists { "lists", "tuple_string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec<(u8, String)>, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -442,7 +442,7 @@ pub mod lists { "lists", "string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -455,7 +455,7 @@ pub mod lists { "lists", "record_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -468,7 +468,7 @@ pub mod lists { "lists", "record_list_reverse", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -481,7 +481,7 @@ pub mod lists { "lists", "variant_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -494,7 +494,7 @@ pub mod lists { "lists", "load_store_everything", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: LoadStoreAllSizes, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/many-arguments.rs b/crates/gen-host/tests/many-arguments.rs index 13873ff9..6077eb78 100644 --- a/crates/gen-host/tests/many-arguments.rs +++ b/crates/gen-host/tests/many-arguments.rs @@ -49,8 +49,8 @@ pub mod many_arguments { ); fn big_argument(&self, x: BigStruct); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -63,7 +63,7 @@ pub mod many_arguments { "many_arguments", "many_args", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a1: u64, a2: u64, a3: u64, @@ -111,7 +111,7 @@ pub mod many_arguments { "many_arguments", "big_argument", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: BigStruct, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/multi-return.rs b/crates/gen-host/tests/multi-return.rs index 1eceb2cf..37ae0a55 100644 --- a/crates/gen-host/tests/multi-return.rs +++ b/crates/gen-host/tests/multi-return.rs @@ -10,8 +10,8 @@ pub mod multi_return { fn mrd(&self) -> u32; fn mre(&self) -> (u32, f32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -24,7 +24,7 @@ pub mod multi_return { "multi_return", "mra", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.mra()) @@ -36,7 +36,7 @@ pub mod multi_return { "multi_return", "mrb", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.mrb()) @@ -48,7 +48,7 @@ pub mod multi_return { "multi_return", "mrc", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.mrc()) @@ -60,7 +60,7 @@ pub mod multi_return { "multi_return", "mrd", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.mrd()) @@ -72,7 +72,7 @@ pub mod multi_return { "multi_return", "mre", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(u32, f32)> { let ctx = get_cx(ctx.data()); Ok(ctx.mre()) diff --git a/crates/gen-host/tests/records.rs b/crates/gen-host/tests/records.rs index 9de4a9a2..b04eb93a 100644 --- a/crates/gen-host/tests/records.rs +++ b/crates/gen-host/tests/records.rs @@ -55,8 +55,8 @@ All of the fields are bool*/ fn aggregate_result(&self) -> Aggregates; fn typedef_inout(&self, e: TupleTypedef2) -> i32; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -69,7 +69,7 @@ All of the fields are bool*/ "records", "tuple_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: (char, u32), | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -82,7 +82,7 @@ All of the fields are bool*/ "records", "tuple_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(char, u32)> { let ctx = get_cx(ctx.data()); Ok(ctx.tuple_result()) @@ -94,7 +94,7 @@ All of the fields are bool*/ "records", "empty_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Empty, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -107,7 +107,7 @@ All of the fields are bool*/ "records", "empty_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.empty_result()) @@ -119,7 +119,7 @@ All of the fields are bool*/ "records", "scalar_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Scalars, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -132,7 +132,7 @@ All of the fields are bool*/ "records", "scalar_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.scalar_result()) @@ -144,7 +144,7 @@ All of the fields are bool*/ "records", "flags_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: ReallyFlags, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -157,7 +157,7 @@ All of the fields are bool*/ "records", "flags_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.flags_result()) @@ -169,7 +169,7 @@ All of the fields are bool*/ "records", "aggregate_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Aggregates, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -182,7 +182,7 @@ All of the fields are bool*/ "records", "aggregate_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.aggregate_result()) @@ -194,7 +194,7 @@ All of the fields are bool*/ "records", "typedef_inout", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, e: TupleTypedef2, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/resources.rs b/crates/gen-host/tests/resources.rs index 394be6d2..d443caae 100644 --- a/crates/gen-host/tests/resources.rs +++ b/crates/gen-host/tests/resources.rs @@ -25,8 +25,8 @@ pub mod resources { fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -39,7 +39,7 @@ pub mod resources { "resources", "constructor_a", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ::tauri_bindgen_host::ResourceId, > { @@ -53,7 +53,7 @@ pub mod resources { "resources", "constructor_b", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ::tauri_bindgen_host::ResourceId, > { diff --git a/crates/gen-host/tests/simple-functions.rs b/crates/gen-host/tests/simple-functions.rs index 39b5e203..d3683d6b 100644 --- a/crates/gen-host/tests/simple-functions.rs +++ b/crates/gen-host/tests/simple-functions.rs @@ -11,8 +11,8 @@ pub mod simple_functions { fn f5(&self) -> (u32, u32); fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -25,7 +25,7 @@ pub mod simple_functions { "simple_functions", "f1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.f1()) @@ -37,7 +37,7 @@ pub mod simple_functions { "simple_functions", "f2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -50,7 +50,7 @@ pub mod simple_functions { "simple_functions", "f3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, b: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { @@ -64,7 +64,7 @@ pub mod simple_functions { "simple_functions", "f4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.f4()) @@ -76,7 +76,7 @@ pub mod simple_functions { "simple_functions", "f5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(u32, u32)> { let ctx = get_cx(ctx.data()); Ok(ctx.f5()) @@ -88,7 +88,7 @@ pub mod simple_functions { "simple_functions", "f6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, b: u32, c: u32, diff --git a/crates/gen-host/tests/simple-lists.rs b/crates/gen-host/tests/simple-lists.rs index 85dd425a..9bbc7c4d 100644 --- a/crates/gen-host/tests/simple-lists.rs +++ b/crates/gen-host/tests/simple-lists.rs @@ -9,8 +9,8 @@ pub mod simple_lists { fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); fn simple_list4(&self, l: Vec>) -> Vec>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod simple_lists { "simple_lists", "simple_list1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, l: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod simple_lists { "simple_lists", "simple_list2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.simple_list2()) @@ -48,7 +48,7 @@ pub mod simple_lists { "simple_lists", "simple_list3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Vec, b: Vec, | -> ::tauri_bindgen_host::anyhow::Result<(Vec, Vec)> { @@ -62,7 +62,7 @@ pub mod simple_lists { "simple_lists", "simple_list4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, l: Vec>, | -> ::tauri_bindgen_host::anyhow::Result>> { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/small-anonymous.rs b/crates/gen-host/tests/small-anonymous.rs index a3e19534..e8a94526 100644 --- a/crates/gen-host/tests/small-anonymous.rs +++ b/crates/gen-host/tests/small-anonymous.rs @@ -12,8 +12,8 @@ pub mod small_anonymous { pub trait SmallAnonymous: Sized { fn option_test(&self) -> Result, Error>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -26,7 +26,7 @@ pub mod small_anonymous { "small_anonymous", "option_test", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result, Error>> { let ctx = get_cx(ctx.data()); Ok(ctx.option_test()) diff --git a/crates/gen-host/tests/strings.rs b/crates/gen-host/tests/strings.rs index 2801adbc..347eda34 100644 --- a/crates/gen-host/tests/strings.rs +++ b/crates/gen-host/tests/strings.rs @@ -8,8 +8,8 @@ pub mod strings { fn b(&self) -> String; fn c(&self, a: String, b: String) -> String; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -22,7 +22,7 @@ pub mod strings { "strings", "a", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: String, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -35,7 +35,7 @@ pub mod strings { "strings", "b", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.b()) @@ -47,7 +47,7 @@ pub mod strings { "strings", "c", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: String, b: String, | -> ::tauri_bindgen_host::anyhow::Result { diff --git a/crates/gen-host/tests/unions.rs b/crates/gen-host/tests/unions.rs index efca91cd..f040f0b8 100644 --- a/crates/gen-host/tests/unions.rs +++ b/crates/gen-host/tests/unions.rs @@ -65,8 +65,8 @@ and is treated that way in some languages*/ ) -> DistinguishableNum; fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -79,7 +79,7 @@ and is treated that way in some languages*/ "unions", "add_one_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllIntegers, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -92,7 +92,7 @@ and is treated that way in some languages*/ "unions", "add_one_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllFloats, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -105,7 +105,7 @@ and is treated that way in some languages*/ "unions", "replace_first_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, text: AllText, letter: char, | -> ::tauri_bindgen_host::anyhow::Result { @@ -119,7 +119,7 @@ and is treated that way in some languages*/ "unions", "identify_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllIntegers, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -132,7 +132,7 @@ and is treated that way in some languages*/ "unions", "identify_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllFloats, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -145,7 +145,7 @@ and is treated that way in some languages*/ "unions", "identify_text", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, text: AllText, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -158,7 +158,7 @@ and is treated that way in some languages*/ "unions", "add_one_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DuplicatedS32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -171,7 +171,7 @@ and is treated that way in some languages*/ "unions", "identify_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DuplicatedS32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -184,7 +184,7 @@ and is treated that way in some languages*/ "unions", "add_one_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DistinguishableNum, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -197,7 +197,7 @@ and is treated that way in some languages*/ "unions", "identify_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DistinguishableNum, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/variants.rs b/crates/gen-host/tests/variants.rs index 87816921..e1d4a344 100644 --- a/crates/gen-host/tests/variants.rs +++ b/crates/gen-host/tests/variants.rs @@ -145,8 +145,8 @@ pub mod variants { fn return_named_option(&self) -> Option; fn return_named_result(&self) -> Result; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -159,7 +159,7 @@ pub mod variants { "variants", "e1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: E1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -172,7 +172,7 @@ pub mod variants { "variants", "e1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.e1_result()) @@ -184,7 +184,7 @@ pub mod variants { "variants", "u1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: U1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -197,7 +197,7 @@ pub mod variants { "variants", "u1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.u1_result()) @@ -209,7 +209,7 @@ pub mod variants { "variants", "v1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: V1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -222,7 +222,7 @@ pub mod variants { "variants", "v1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.v1_result()) @@ -234,7 +234,7 @@ pub mod variants { "variants", "bool_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: bool, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -247,7 +247,7 @@ pub mod variants { "variants", "bool_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.bool_result()) @@ -259,7 +259,7 @@ pub mod variants { "variants", "option_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Option, b: Option<()>, c: Option, @@ -278,7 +278,7 @@ pub mod variants { "variants", "option_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ( Option, @@ -300,7 +300,7 @@ pub mod variants { "variants", "casts", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Casts1, b: Casts2, c: Casts3, @@ -320,7 +320,7 @@ pub mod variants { "variants", "result_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Result<(), ()>, b: Result<(), E1>, c: Result, @@ -338,7 +338,7 @@ pub mod variants { "variants", "result_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ( Result<(), ()>, @@ -359,7 +359,7 @@ pub mod variants { "variants", "return_result_sugar", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar()) @@ -371,7 +371,7 @@ pub mod variants { "variants", "return_result_sugar2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar2()) @@ -383,7 +383,7 @@ pub mod variants { "variants", "return_result_sugar3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar3()) @@ -395,7 +395,7 @@ pub mod variants { "variants", "return_result_sugar4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar4()) @@ -407,7 +407,7 @@ pub mod variants { "variants", "return_option_sugar", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar()) @@ -419,7 +419,7 @@ pub mod variants { "variants", "return_option_sugar2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar2()) @@ -431,7 +431,7 @@ pub mod variants { "variants", "result_simple", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.result_simple()) @@ -443,7 +443,7 @@ pub mod variants { "variants", "is_clone_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: IsClone, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -456,7 +456,7 @@ pub mod variants { "variants", "is_clone_return", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.is_clone_return()) @@ -468,7 +468,7 @@ pub mod variants { "variants", "return_named_option", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_option()) @@ -480,7 +480,7 @@ pub mod variants { "variants", "return_named_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_result()) diff --git a/crates/host/Cargo.toml b/crates/host/Cargo.toml index 59b29848..6a1dd311 100644 --- a/crates/host/Cargo.toml +++ b/crates/host/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true bitflags.workspace = true tauri-bindgen-host-macro = { path = "../host-macro" } async-trait = "0.1.73" -tauri = "1.4.1" +tauri.workspace = true tracing = { version = "0.1.37", features = ["log", "log-always"] } anyhow = "1.0.75" serde.workspace = true diff --git a/crates/ipc-router-wip/Cargo.toml b/crates/ipc-router-wip/Cargo.toml index 99a79fd7..ccf580b9 100644 --- a/crates/ipc-router-wip/Cargo.toml +++ b/crates/ipc-router-wip/Cargo.toml @@ -12,5 +12,5 @@ anyhow = "1.0.75" serde.workspace = true log.workspace = true postcard = { version = "1.0.7", features = ["alloc"] } -tauri = "1.4.1" -url = "2.4.1" +tauri.workspace = true +tokio = { version = "1.32.0", features = ["sync", "macros"] } diff --git a/crates/ipc-router-wip/src/lib.rs b/crates/ipc-router-wip/src/lib.rs index 014a0d96..13253608 100644 --- a/crates/ipc-router-wip/src/lib.rs +++ b/crates/ipc-router-wip/src/lib.rs @@ -4,31 +4,42 @@ pub use anyhow::Error; use anyhow::{bail, Result}; use std::{ collections::{hash_map::Entry, HashMap}, - sync::{mpsc::Sender, Arc, Mutex}, + sync::Arc, +}; +use tauri::{ + http::{header::CONTENT_TYPE, Request, Response, StatusCode}, + AppHandle, Runtime, +}; +use tokio::sync::{ + mpsc, + oneshot::{self, Sender}, }; -use tauri::{AppHandle, Manager, Runtime}; -use url::Url; #[derive(Default)] -pub struct Router { +pub struct Router { data: Arc, string2idx: HashMap, usize>, strings: Vec>, - map: HashMap>, + map: HashMap>, } -pub type Definition = - Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; +pub type Definition = + Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; -pub struct Caller<'a, T> { +pub struct Caller<'a, T, R: Runtime> { data: &'a T, + app_handle: AppHandle, } -impl<'a, T> Caller<'a, T> { +impl<'a, T, R: Runtime> Caller<'a, T, R> { #[must_use] pub fn data(&self) -> &T { self.data } + #[must_use] + pub fn app_handle(&self) -> &AppHandle { + &self.app_handle + } } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] @@ -37,7 +48,7 @@ struct ImportKey { name: usize, } -impl Router { +impl Router { #[must_use] pub fn new(data: U) -> Self { Self { @@ -52,7 +63,7 @@ impl Router { &mut self, module: &str, name: &str, - func: impl IntoFunc, + func: impl IntoFunc, ) -> Result<&mut Self> { let func = func.into_func(); @@ -67,7 +78,8 @@ impl Router { module: Option>, name: impl AsRef, params: &[u8], - res_tx: Sender>, + app_handle: AppHandle, + tx: Sender>, ) -> anyhow::Result<()> { let key = self.import_key(module, name.as_ref()); @@ -76,14 +88,17 @@ impl Router { .get(&key) .ok_or(anyhow::anyhow!("method not found"))?; - let caller = Caller { data: &*self.data }; + let caller = Caller { + data: &*self.data, + app_handle, + }; - handler(caller, params, res_tx)?; + handler(caller, params, tx)?; Ok(()) } - fn insert(&mut self, key: ImportKey, item: Definition) -> Result<()> { + fn insert(&mut self, key: ImportKey, item: Definition) -> Result<()> { match self.map.entry(key) { Entry::Occupied(_) => { let module = &self.strings[key.module]; @@ -119,9 +134,9 @@ impl Router { } } -pub trait IntoFunc: Send + Sync { +pub trait IntoFunc: Send + Sync { #[doc(hidden)] - fn into_func(self) -> Definition; + fn into_func(self) -> Definition; } macro_rules! impl_into_func { @@ -130,14 +145,14 @@ macro_rules! impl_into_func { // delegating to the implementation below which does have the leading // `Caller` parameter. #[allow(non_snake_case)] - impl IntoFunc for F + impl IntoFunc for F where F: Fn($($params),*) -> anyhow::Result + Send + Sync + 'static, $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize + R: serde::Serialize, { - fn into_func(self) -> Definition { - let f = move |_: Caller, $($params:$params),*| { + fn into_func(self) -> Definition { + let f = move |_: Caller, $($params:$params),*| { self($($params),*) }; @@ -146,13 +161,13 @@ macro_rules! impl_into_func { } #[allow(non_snake_case)] - impl IntoFunc, $($params,)*), R> for F + impl IntoFunc, $($params,)*), R, Rt> for F where - F: Fn(Caller, $($params),*) -> anyhow::Result + Send + Sync + 'static, + F: Fn(Caller, $($params),*) -> anyhow::Result + Send + Sync + 'static, $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize + R: serde::Serialize, { - fn into_func(self) -> Definition { + fn into_func(self) -> Definition { Box::new(move |caller, params, tx| { log::debug!("Deserializing parameters..."); let ($($params,)*) = postcard::from_bytes(params)?; @@ -163,7 +178,7 @@ macro_rules! impl_into_func { log::debug!("Serializing response..."); let out = postcard::to_allocvec(&out)?; - tx.send(out)?; + tx.send(out).unwrap(); Ok(()) }) @@ -196,66 +211,87 @@ macro_rules! for_each_function_signature { for_each_function_signature!(impl_into_func); -pub trait BuilderExt { +pub trait BuilderExt { #[must_use] - fn ipc_router(self, router: Router) -> Self; + fn ipc_router(self, router: Router) -> Self; } -impl BuilderExt for tauri::Builder { - fn ipc_router(self, router: Router) -> Self { - self.manage(Mutex::new(router)) - .register_uri_scheme_protocol("ipc", |app, req| { - let res = uri_scheme_handler_inner::(app, req); +impl BuilderExt for tauri::Builder { + fn ipc_router(self, mut router: Router) -> Self { + let (tx, mut rx) = mpsc::channel::<(AppHandle, Request>, _)>(250); + + let this = + self.register_asynchronous_uri_scheme_protocol("ipc", move |app, req, responder| { + tx.try_send((app.clone(), req, responder)).unwrap(); + }); + + tauri::async_runtime::handle().spawn(async move { + while let Some((app, req, responder)) = rx.recv().await { + let path = req.uri().path().strip_prefix('/').unwrap(); + + let (module, method) = path + .split_once('/') + .map_or((None, path), |(module, method)| (Some(module), method)); + + log::debug!("ipc request for {:?}::{}", module, method); + + let (tx, rx) = oneshot::channel(); + router + .handle_request(module, method, req.body(), app, tx) + .unwrap(); + let res = rx.await; log::debug!("call result {:?}", res); - let mut resp = match res { + let mut response = match res { Ok(val) => { - let mut resp = tauri::http::Response::new(val); - resp.set_status(tauri::http::status::StatusCode::OK); - resp.set_mimetype(Some("application/octet-stream".to_string())); - resp - } - Err(err) => { - let mut resp = tauri::http::Response::new(err.to_string().into_bytes()); - resp.set_status(tauri::http::status::StatusCode::BAD_REQUEST); - resp + let mut resp = Response::builder().status(StatusCode::OK); + resp.headers_mut().unwrap().insert( + CONTENT_TYPE, + tauri::http::header::HeaderValue::from_static( + "application/octet-stream", + ), + ); + resp.body(val).unwrap() } + Err(err) => Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(err.to_string().into_bytes()) + .unwrap(), }; - resp.headers_mut().insert( + response.headers_mut().insert( tauri::http::header::ACCESS_CONTROL_ALLOW_ORIGIN, tauri::http::header::HeaderValue::from_static("*"), ); - log::trace!("sending response {:?}", resp); + responder.respond(response); + } + }); - Ok(resp) - }) + this } } -fn uri_scheme_handler_inner( - app: &AppHandle, - req: &tauri::http::Request, -) -> anyhow::Result> { - let url = Url::parse(req.uri())?; - - let path = url.path().strip_prefix('/').unwrap(); +// async fn uri_scheme_handler_inner( +// app: &AppHandle, +// req: &tauri::http::Request>, +// ) -> anyhow::Result> { +// let path = req.uri().path().strip_prefix('/').unwrap(); - let (module, method) = path - .split_once('/') - .map_or((None, path), |(module, method)| (Some(module), method)); +// let (module, method) = path +// .split_once('/') +// .map_or((None, path), |(module, method)| (Some(module), method)); - log::debug!("ipc request for {:?}::{}", module, method); +// log::debug!("ipc request for {:?}::{}", module, method); - let (res_tx, res_rx) = std::sync::mpsc::channel(); +// let (res_tx, res_rx) = oneshot::channel(); - let router = app.state::>>(); - let mut router = router.lock().unwrap(); +// let router = app.state::>>(); +// let mut router = router.lock().unwrap(); - // this is terrible we should not clone here - router.handle_request(module, method, req.body(), res_tx)?; +// // this is terrible we should not clone here +// router.handle_request(module, method, req.body(), res_tx)?; - Ok(res_rx.recv()?) -} +// Ok(res_rx.await?) +// } diff --git a/examples/greet/src-tauri/Cargo.toml b/examples/greet/src-tauri/Cargo.toml index eea277ed..c9951201 100644 --- a/examples/greet/src-tauri/Cargo.toml +++ b/examples/greet/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { version = "1.1", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2.4", features = ["api-all"] } +tauri = { git = "https://github.com/tauri-apps/tauri" } tauri-bindgen-host = { path = "../../../crates/host" } tracing-subscriber = "0.3.16" tracing = "0.1.37" diff --git a/examples/greet/src-tauri/tauri.conf.json b/examples/greet/src-tauri/tauri.conf.json index 15e818eb..828dc275 100644 --- a/examples/greet/src-tauri/tauri.conf.json +++ b/examples/greet/src-tauri/tauri.conf.json @@ -11,9 +11,6 @@ "version": "0.0.0" }, "tauri": { - "allowlist": { - "all": true - }, "bundle": { "active": true, "category": "DeveloperTool", @@ -50,9 +47,6 @@ "security": { "csp": null }, - "updater": { - "active": false - }, "windows": [ { "fullscreen": false, From 58f06a0237c998ece4c9ee7a68f1d28eb85e82d8 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Tue, 12 Sep 2023 16:03:30 +0200 Subject: [PATCH 2/7] wip --- crates/gen-host/src/lib.rs | 121 ++-- crates/gen-host/tests/async/chars.rs | 51 ++ crates/gen-host/tests/async/conventions.rs | 198 +++++++ crates/gen-host/tests/async/empty.rs | 20 + crates/gen-host/tests/async/flegs.rs | 174 ++++++ crates/gen-host/tests/async/floats.rs | 77 +++ crates/gen-host/tests/async/integers.rs | 348 +++++++++++ crates/gen-host/tests/async/lists.rs | 552 ++++++++++++++++++ crates/gen-host/tests/async/many-arguments.rs | 135 +++++ crates/gen-host/tests/async/multi-return.rs | 91 +++ crates/gen-host/tests/async/records.rs | 226 +++++++ crates/gen-host/tests/async/resources.rs | 69 +++ .../gen-host/tests/async/simple-functions.rs | 111 ++++ crates/gen-host/tests/async/simple-lists.rs | 83 +++ .../gen-host/tests/async/small-anonymous.rs | 41 ++ crates/gen-host/tests/async/strings.rs | 66 +++ crates/gen-host/tests/async/unions.rs | 238 ++++++++ crates/gen-host/tests/async/variants.rs | 497 ++++++++++++++++ crates/gen-host/tests/codegen-async.rs | 272 +++++++++ .../tests/{codegen.rs => codegen-sync.rs} | 32 +- crates/gen-host/tests/strings.rs | 55 +- crates/gen-host/tests/{ => sync}/chars.rs | 19 +- .../gen-host/tests/{ => sync}/conventions.rs | 80 +-- crates/gen-host/tests/{ => sync}/empty.rs | 4 +- crates/gen-host/tests/{ => sync}/flegs.rs | 67 +-- crates/gen-host/tests/{ => sync}/floats.rs | 34 +- crates/gen-host/tests/{ => sync}/integers.rs | 179 ++---- crates/gen-host/tests/{ => sync}/lists.rs | 272 ++++----- .../tests/{ => sync}/many-arguments.rs | 86 +-- .../gen-host/tests/{ => sync}/multi-return.rs | 34 +- crates/gen-host/tests/{ => sync}/records.rs | 92 ++- crates/gen-host/tests/{ => sync}/resources.rs | 20 +- .../tests/{ => sync}/simple-functions.rs | 54 +- .../gen-host/tests/{ => sync}/simple-lists.rs | 40 +- .../tests/{ => sync}/small-anonymous.rs | 10 +- crates/gen-host/tests/sync/strings.rs | 56 ++ crates/gen-host/tests/{ => sync}/unions.rs | 104 ++-- crates/gen-host/tests/{ => sync}/variants.rs | 223 +++---- crates/ipc-router-wip/Cargo.toml | 1 + crates/ipc-router-wip/src/lib.rs | 324 +++++----- examples/greet/src-tauri/Cargo.toml | 2 +- examples/greet/src-tauri/src/main.rs | 5 +- update-fixtures.sh | 4 +- 43 files changed, 4104 insertions(+), 1063 deletions(-) create mode 100644 crates/gen-host/tests/async/chars.rs create mode 100644 crates/gen-host/tests/async/conventions.rs create mode 100644 crates/gen-host/tests/async/empty.rs create mode 100644 crates/gen-host/tests/async/flegs.rs create mode 100644 crates/gen-host/tests/async/floats.rs create mode 100644 crates/gen-host/tests/async/integers.rs create mode 100644 crates/gen-host/tests/async/lists.rs create mode 100644 crates/gen-host/tests/async/many-arguments.rs create mode 100644 crates/gen-host/tests/async/multi-return.rs create mode 100644 crates/gen-host/tests/async/records.rs create mode 100644 crates/gen-host/tests/async/resources.rs create mode 100644 crates/gen-host/tests/async/simple-functions.rs create mode 100644 crates/gen-host/tests/async/simple-lists.rs create mode 100644 crates/gen-host/tests/async/small-anonymous.rs create mode 100644 crates/gen-host/tests/async/strings.rs create mode 100644 crates/gen-host/tests/async/unions.rs create mode 100644 crates/gen-host/tests/async/variants.rs create mode 100644 crates/gen-host/tests/codegen-async.rs rename crates/gen-host/tests/{codegen.rs => codegen-sync.rs} (83%) rename crates/gen-host/tests/{ => sync}/chars.rs (69%) rename crates/gen-host/tests/{ => sync}/conventions.rs (65%) rename crates/gen-host/tests/{ => sync}/empty.rs (81%) rename crates/gen-host/tests/{ => sync}/flegs.rs (75%) rename crates/gen-host/tests/{ => sync}/floats.rs (63%) rename crates/gen-host/tests/{ => sync}/integers.rs (56%) rename crates/gen-host/tests/{ => sync}/lists.rs (62%) rename crates/gen-host/tests/{ => sync}/many-arguments.rs (62%) rename crates/gen-host/tests/{ => sync}/multi-return.rs (65%) rename crates/gen-host/tests/{ => sync}/records.rs (69%) rename crates/gen-host/tests/{ => sync}/resources.rs (76%) rename crates/gen-host/tests/{ => sync}/simple-functions.rs (64%) rename crates/gen-host/tests/{ => sync}/simple-lists.rs (66%) rename crates/gen-host/tests/{ => sync}/small-anonymous.rs (78%) create mode 100644 crates/gen-host/tests/sync/strings.rs rename crates/gen-host/tests/{ => sync}/unions.rs (72%) rename crates/gen-host/tests/{ => sync}/variants.rs (65%) diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index a0c8a066..310dac03 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -10,12 +10,12 @@ use std::path::PathBuf; use heck::ToKebabCase; use heck::{ToSnakeCase, ToUpperCamelCase}; -use proc_macro2::TokenStream; +use proc_macro2::{Literal, TokenStream}; use quote::format_ident; use quote::quote; use tauri_bindgen_core::{Generate, GeneratorBuilder, TypeInfo, TypeInfos}; use tauri_bindgen_gen_rust::{print_generics, BorrowMode, FnSig, RustGenerator}; -use wit_parser::{Function, FunctionResult, Interface, Type, TypeDefKind}; +use wit_parser::{Function, Interface, Type, TypeDefKind}; #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "clap", derive(clap::Args))] @@ -237,7 +237,7 @@ impl Host { let functions = functions.map(|func| { let sig = FnSig { - async_: false, + async_: self.opts.async_, unsafe_: false, private: true, self_arg: Some(quote!(&self)), @@ -251,7 +251,13 @@ impl Host { let sized = sized.then_some(quote!(: Sized)); + let async_trait = self + .opts + .async_ + .then_some(quote! { #[::tauri_bindgen_host::async_trait] }); + quote! { + #async_trait pub trait #ident #sized { #(#additional_items)* #(#functions)* @@ -302,54 +308,97 @@ impl Host { let func_name = func.ident.to_snake_case(); let func_ident = format_ident!("{}", func_name); - let params = self.print_function_params(&func.params, &BorrowMode::Owned); - - let param_idents = func - .params - .iter() - .map(|(ident, _)| { format_ident!("{}", ident) }); - - let result = match func.result.as_ref() { - Some(FunctionResult::Anon(ty)) => { - let ty = self.print_ty(ty, &BorrowMode::Owned); - + let param_decl = match func.params.len() { + 0 => quote! { () }, + 1 => { + let ty = &func.params.first().unwrap().1; + let ty = self.print_ty(ty, &BorrowMode::Owned); quote! { #ty } } - Some(FunctionResult::Named(types)) if types.len() == 1 => { - let (_, ty) = &types[0]; - let ty = self.print_ty(ty, &BorrowMode::Owned); - - quote! { #ty } + _ => { + let tys = func + .params + .iter() + .map(|(_, ty)| { self.print_ty(ty, &BorrowMode::Owned) }); + quote! { (#(#tys),*) } } - Some(FunctionResult::Named(types)) => { - let types = types.iter().map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); + }; - quote! { (#(#types),*) } + let param_acc = match func.params.len() { + 0 => quote! { }, + 1 => quote! { p }, + _ => { + let ids = func + .params + .iter() + .enumerate() + .map(|(i, _)| { + let i = Literal::usize_unsuffixed(i); + quote! { p.#i } + }); + quote! { #(#ids),* } } - _ => quote! { () }, }; - quote! { - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router.func_wrap( - #mod_name, - #func_name, - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, #params| -> ::tauri_bindgen_host::anyhow::Result<#result> { - let ctx = get_cx(ctx.data()); - - Ok(ctx.#func_ident(#(#param_idents),*)) - }, - )?; + // let result = match func.result.as_ref() { + // Some(FunctionResult::Anon(ty)) => { + // let ty = self.print_ty(ty, &BorrowMode::Owned); + + // quote! { #ty } + // } + // Some(FunctionResult::Named(types)) if types.len() == 1 => { + // let (_, ty) = &types[0]; + // let ty = self.print_ty(ty, &BorrowMode::Owned); + + // quote! { #ty } + // } + // Some(FunctionResult::Named(types)) => { + // let types = types.iter().map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); + + // quote! { (#(#types),*) } + // } + // _ => quote! { () }, + // }; + + if self.opts.async_ { + quote! { + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router.define_async( + #mod_name, + #func_name, + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.#func_ident(#param_acc).await) + }) + })?; + } + } else { + quote! { + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router.define( + #mod_name, + #func_name, + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { + let ctx = get_cx(ctx.data()); + + Ok(ctx.#func_ident(#param_acc)) + }, + )?; + } } }); quote! { - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: #trait_ident + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); diff --git a/crates/gen-host/tests/async/chars.rs b/crates/gen-host/tests/async/chars.rs new file mode 100644 index 00000000..efe39e74 --- /dev/null +++ b/crates/gen-host/tests/async/chars.rs @@ -0,0 +1,51 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod chars { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait Chars: Sized { + ///A function that accepts a character + async fn take_char(&self, x: char); + ///A function that returns a character + async fn return_char(&self) -> char; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Chars + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "chars", + "take_char", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: char| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.take_char(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "chars", + "return_char", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_char().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/conventions.rs b/crates/gen-host/tests/async/conventions.rs new file mode 100644 index 00000000..fd2fc471 --- /dev/null +++ b/crates/gen-host/tests/async/conventions.rs @@ -0,0 +1,198 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod conventions { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Deserialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct LudicrousSpeed { + pub how_fast_are_you_going: u32, + pub i_am_going_extremely_slow: u64, + } + #[::tauri_bindgen_host::async_trait] + pub trait Conventions: Sized { + async fn kebab_case(&self); + async fn foo(&self, x: LudicrousSpeed); + async fn function_with_underscores(&self); + async fn function_with_no_weird_characters(&self); + async fn apple(&self); + async fn apple_pear(&self); + async fn apple_pear_grape(&self); + async fn a0(&self); + async fn is_xml(&self); + async fn explicit(&self); + async fn explicit_snake(&self); + async fn bool(&self); + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Conventions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "kebab_case", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.kebab_case().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "foo", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: LudicrousSpeed| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.foo(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "function_with_underscores", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.function_with_underscores().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "function_with_no_weird_characters", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.function_with_no_weird_characters().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "apple", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.apple().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "apple_pear", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.apple_pear().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "apple_pear_grape", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.apple_pear_grape().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "a0", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a0().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "is_xml", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.is_xml().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "explicit", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.explicit().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "explicit_snake", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.explicit_snake().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "conventions", + "bool", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.bool().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/empty.rs b/crates/gen-host/tests/async/empty.rs new file mode 100644 index 00000000..304c03ac --- /dev/null +++ b/crates/gen-host/tests/async/empty.rs @@ -0,0 +1,20 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod empty { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait Empty: Sized {} + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Empty + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/flegs.rs b/crates/gen-host/tests/async/flegs.rs new file mode 100644 index 00000000..fb6d24a3 --- /dev/null +++ b/crates/gen-host/tests/async/flegs.rs @@ -0,0 +1,174 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod flegs { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag1 : u8 { const B0 + = 1 << 0; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag2 : u8 { const B0 + = 1 << 0; const B1 = 1 << 1; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag4 : u8 { const B0 + = 1 << 0; const B1 = 1 << 1; const B2 = 1 << 2; const B3 = 1 << 3; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag8 : u8 { const B0 + = 1 << 0; const B1 = 1 << 1; const B2 = 1 << 2; const B3 = 1 << 3; const B4 = 1 + << 4; const B5 = 1 << 5; const B6 = 1 << 6; const B7 = 1 << 7; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag16 : u16 { const + B0 = 1 << 0; const B1 = 1 << 1; const B2 = 1 << 2; const B3 = 1 << 3; const B4 = + 1 << 4; const B5 = 1 << 5; const B6 = 1 << 6; const B7 = 1 << 7; const B8 = 1 << + 8; const B9 = 1 << 9; const B10 = 1 << 10; const B11 = 1 << 11; const B12 = 1 << + 12; const B13 = 1 << 13; const B14 = 1 << 14; const B15 = 1 << 15; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag32 : u32 { const + B0 = 1 << 0; const B1 = 1 << 1; const B2 = 1 << 2; const B3 = 1 << 3; const B4 = + 1 << 4; const B5 = 1 << 5; const B6 = 1 << 6; const B7 = 1 << 7; const B8 = 1 << + 8; const B9 = 1 << 9; const B10 = 1 << 10; const B11 = 1 << 11; const B12 = 1 << + 12; const B13 = 1 << 13; const B14 = 1 << 14; const B15 = 1 << 15; const B16 = 1 + << 16; const B17 = 1 << 17; const B18 = 1 << 18; const B19 = 1 << 19; const B20 = + 1 << 20; const B21 = 1 << 21; const B22 = 1 << 22; const B23 = 1 << 23; const B24 + = 1 << 24; const B25 = 1 << 25; const B26 = 1 << 26; const B27 = 1 << 27; const + B28 = 1 << 28; const B29 = 1 << 29; const B30 = 1 << 30; const B31 = 1 << 31; } + } + bitflags::bitflags! { + #[derive(serde::Deserialize, serde::Serialize)] pub struct Flag64 : u64 { const + B0 = 1 << 0; const B1 = 1 << 1; const B2 = 1 << 2; const B3 = 1 << 3; const B4 = + 1 << 4; const B5 = 1 << 5; const B6 = 1 << 6; const B7 = 1 << 7; const B8 = 1 << + 8; const B9 = 1 << 9; const B10 = 1 << 10; const B11 = 1 << 11; const B12 = 1 << + 12; const B13 = 1 << 13; const B14 = 1 << 14; const B15 = 1 << 15; const B16 = 1 + << 16; const B17 = 1 << 17; const B18 = 1 << 18; const B19 = 1 << 19; const B20 = + 1 << 20; const B21 = 1 << 21; const B22 = 1 << 22; const B23 = 1 << 23; const B24 + = 1 << 24; const B25 = 1 << 25; const B26 = 1 << 26; const B27 = 1 << 27; const + B28 = 1 << 28; const B29 = 1 << 29; const B30 = 1 << 30; const B31 = 1 << 31; + const B32 = 1 << 32; const B33 = 1 << 33; const B34 = 1 << 34; const B35 = 1 << + 35; const B36 = 1 << 36; const B37 = 1 << 37; const B38 = 1 << 38; const B39 = 1 + << 39; const B40 = 1 << 40; const B41 = 1 << 41; const B42 = 1 << 42; const B43 = + 1 << 43; const B44 = 1 << 44; const B45 = 1 << 45; const B46 = 1 << 46; const B47 + = 1 << 47; const B48 = 1 << 48; const B49 = 1 << 49; const B50 = 1 << 50; const + B51 = 1 << 51; const B52 = 1 << 52; const B53 = 1 << 53; const B54 = 1 << 54; + const B55 = 1 << 55; const B56 = 1 << 56; const B57 = 1 << 57; const B58 = 1 << + 58; const B59 = 1 << 59; const B60 = 1 << 60; const B61 = 1 << 61; const B62 = 1 + << 62; const B63 = 1 << 63; } + } + #[::tauri_bindgen_host::async_trait] + pub trait Flegs: Sized { + async fn roundtrip_flag1(&self, x: Flag1) -> Flag1; + async fn roundtrip_flag2(&self, x: Flag2) -> Flag2; + async fn roundtrip_flag4(&self, x: Flag4) -> Flag4; + async fn roundtrip_flag8(&self, x: Flag8) -> Flag8; + async fn roundtrip_flag16(&self, x: Flag16) -> Flag16; + async fn roundtrip_flag32(&self, x: Flag32) -> Flag32; + async fn roundtrip_flag64(&self, x: Flag64) -> Flag64; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Flegs + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag1", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag1| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag1(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag2| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag2(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag4", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag4| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag4(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag8", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag8| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag8(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag16", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag16| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag16(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag32", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag32| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag32(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "flegs", + "roundtrip_flag64", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag64| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.roundtrip_flag64(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/floats.rs b/crates/gen-host/tests/async/floats.rs new file mode 100644 index 00000000..7417146d --- /dev/null +++ b/crates/gen-host/tests/async/floats.rs @@ -0,0 +1,77 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod floats { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait Floats: Sized { + async fn float32_param(&self, x: f32); + async fn float64_param(&self, x: f64); + async fn float32_result(&self) -> f32; + async fn float64_result(&self) -> f64; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Floats + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "floats", + "float32_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: f32| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.float32_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "floats", + "float64_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: f64| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.float64_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "floats", + "float32_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.float32_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "floats", + "float64_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.float64_result().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/integers.rs b/crates/gen-host/tests/async/integers.rs new file mode 100644 index 00000000..91cf91ce --- /dev/null +++ b/crates/gen-host/tests/async/integers.rs @@ -0,0 +1,348 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod integers { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait Integers: Sized { + async fn a1(&self, x: u8); + async fn a2(&self, x: i8); + async fn a3(&self, x: u16); + async fn a4(&self, x: i16); + async fn a5(&self, x: u32); + async fn a6(&self, x: i32); + async fn a7(&self, x: u64); + async fn a8(&self, x: i64); + async fn a9(&self, x: u128); + async fn a10(&self, x: i128); + async fn a11( + &self, + p1: u8, + p2: i8, + p3: u16, + p4: i16, + p5: u32, + p6: i32, + p7: u64, + p8: i64, + p9: u128, + p10: i128, + ); + async fn r1(&self) -> u8; + async fn r2(&self) -> i8; + async fn r3(&self) -> u16; + async fn r4(&self) -> i16; + async fn r5(&self) -> u32; + async fn r6(&self) -> i32; + async fn r7(&self) -> u64; + async fn r8(&self) -> i64; + async fn r9(&self) -> u128; + async fn r10(&self) -> i128; + async fn pair_ret(&self) -> (i64, u8); + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Integers + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a1", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u8| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a1(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i8| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a2(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a3", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u16| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a3(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a4", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i16| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a4(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a5", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u32| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a5(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a6", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i32| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a6(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a7", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u64| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a7(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a8", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i64| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a8(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a9", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u128| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a9(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a10", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i128| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a10(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "a11", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok( + ctx + .a11(p.0, p.1, p.2, p.3, p.4, p.5, p.6, p.7, p.8, p.9) + .await, + ) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r1", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r1().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r2().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r3", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r3().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r4", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r4().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r5", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r5().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r6", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r6().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r7", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r7().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r8", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r8().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r9", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r9().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "r10", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.r10().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "integers", + "pair_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.pair_ret().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/lists.rs b/crates/gen-host/tests/async/lists.rs new file mode 100644 index 00000000..f6ed020b --- /dev/null +++ b/crates/gen-host/tests/async/lists.rs @@ -0,0 +1,552 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod lists { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct OtherRecord { + pub a1: u32, + pub a2: u64, + pub a3: i32, + pub a4: i64, + pub b: String, + pub c: Vec, + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct SomeRecord { + pub x: String, + pub y: OtherRecord, + pub z: Vec, + pub c1: u32, + pub c2: u64, + pub c3: i32, + pub c4: i64, + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum OtherVariant { + A, + B(u32), + C(String), + } + #[derive(serde::Deserialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum SomeVariant { + A(String), + B, + C(u32), + D(Vec), + } + pub type LoadStoreAllSizes = Vec< + (String, u8, i8, u16, i16, u32, i32, u64, i64, f32, f64, char), + >; + #[::tauri_bindgen_host::async_trait] + pub trait Lists: Sized { + async fn list_u8_param(&self, x: Vec); + async fn list_u16_param(&self, x: Vec); + async fn list_u32_param(&self, x: Vec); + async fn list_u64_param(&self, x: Vec); + async fn list_u128_param(&self, x: Vec); + async fn list_s8_param(&self, x: Vec); + async fn list_s16_param(&self, x: Vec); + async fn list_s32_param(&self, x: Vec); + async fn list_s64_param(&self, x: Vec); + async fn list_s128_param(&self, x: Vec); + async fn list_float32_param(&self, x: Vec); + async fn list_float64_param(&self, x: Vec); + async fn list_u8_ret(&self) -> Vec; + async fn list_u16_ret(&self) -> Vec; + async fn list_u32_ret(&self) -> Vec; + async fn list_u64_ret(&self) -> Vec; + async fn list_u128_ret(&self) -> Vec; + async fn list_s8_ret(&self) -> Vec; + async fn list_s16_ret(&self) -> Vec; + async fn list_s32_ret(&self) -> Vec; + async fn list_s64_ret(&self) -> Vec; + async fn list_s128_ret(&self) -> Vec; + async fn list_float32_ret(&self) -> Vec; + async fn list_float64_ret(&self) -> Vec; + async fn tuple_list(&self, x: Vec<(u8, i8)>) -> Vec<(i64, u32)>; + async fn string_list_arg(&self, a: Vec); + async fn string_list_ret(&self) -> Vec; + async fn tuple_string_list(&self, x: Vec<(u8, String)>) -> Vec<(String, u8)>; + async fn string_list(&self, x: Vec) -> Vec; + async fn record_list(&self, x: Vec) -> Vec; + async fn record_list_reverse(&self, x: Vec) -> Vec; + async fn variant_list(&self, x: Vec) -> Vec; + async fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Lists + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u8_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u8_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u16_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u16_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u32_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u32_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u64_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u64_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u128_param", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u128_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s8_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s8_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s16_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s16_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s32_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s32_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s64_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s64_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s128_param", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s128_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_float32_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_float32_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_float64_param", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_float64_param(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u8_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u8_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u16_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u16_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u32_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u32_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u64_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u64_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_u128_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_u128_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s8_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s8_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s16_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s16_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s32_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s32_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s64_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s64_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_s128_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_s128_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_float32_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_float32_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "list_float64_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.list_float64_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "tuple_list", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec<(u8, i8)>| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.tuple_list(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "string_list_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.string_list_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "string_list_ret", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.string_list_ret().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "tuple_string_list", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec<(u8, String)>| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.tuple_string_list(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "string_list", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.string_list(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "record_list", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.record_list(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "record_list_reverse", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.record_list_reverse(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "variant_list", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.variant_list(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "lists", + "load_store_everything", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: LoadStoreAllSizes| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.load_store_everything(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/many-arguments.rs b/crates/gen-host/tests/async/many-arguments.rs new file mode 100644 index 00000000..7ea4fcc5 --- /dev/null +++ b/crates/gen-host/tests/async/many-arguments.rs @@ -0,0 +1,135 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod many_arguments { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Deserialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct BigStruct { + pub a1: String, + pub a2: String, + pub a3: String, + pub a4: String, + pub a5: String, + pub a6: String, + pub a7: String, + pub a8: String, + pub a9: String, + pub a10: String, + pub a11: String, + pub a12: String, + pub a13: String, + pub a14: String, + pub a15: String, + pub a16: String, + pub a17: String, + pub a18: String, + pub a19: String, + pub a20: String, + } + #[::tauri_bindgen_host::async_trait] + pub trait ManyArguments: Sized { + async fn many_args( + &self, + a1: u64, + a2: u64, + a3: u64, + a4: u64, + a5: u64, + a6: u64, + a7: u64, + a8: u64, + a9: u64, + a10: u64, + a11: u64, + a12: u64, + a13: u64, + a14: u64, + a15: u64, + a16: u64, + ); + async fn big_argument(&self, x: BigStruct); + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: ManyArguments + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "many_arguments", + "many_args", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + )| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok( + ctx + .many_args( + p.0, + p.1, + p.2, + p.3, + p.4, + p.5, + p.6, + p.7, + p.8, + p.9, + p.10, + p.11, + p.12, + p.13, + p.14, + p.15, + ) + .await, + ) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "many_arguments", + "big_argument", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: BigStruct| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.big_argument(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/multi-return.rs b/crates/gen-host/tests/async/multi-return.rs new file mode 100644 index 00000000..729cf8ff --- /dev/null +++ b/crates/gen-host/tests/async/multi-return.rs @@ -0,0 +1,91 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod multi_return { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait MultiReturn: Sized { + async fn mra(&self); + async fn mrb(&self); + async fn mrc(&self) -> u32; + async fn mrd(&self) -> u32; + async fn mre(&self) -> (u32, f32); + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: MultiReturn + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "multi_return", + "mra", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.mra().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "multi_return", + "mrb", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.mrb().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "multi_return", + "mrc", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.mrc().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "multi_return", + "mrd", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.mrd().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "multi_return", + "mre", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.mre().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/records.rs b/crates/gen-host/tests/async/records.rs new file mode 100644 index 00000000..d9c306eb --- /dev/null +++ b/crates/gen-host/tests/async/records.rs @@ -0,0 +1,226 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod records { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct Empty {} + /**A record containing two scalar fields +that both have the same type*/ + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct Scalars { + ///The first field, named a + pub a: u32, + ///The second field, named b + pub b: u32, + } + /**A record that is really just flags +All of the fields are bool*/ + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct ReallyFlags { + pub a: bool, + pub b: bool, + pub c: bool, + pub d: bool, + pub e: bool, + pub f: bool, + pub g: bool, + pub h: bool, + pub i: bool, + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct Aggregates { + pub a: Scalars, + pub b: u32, + pub c: Empty, + pub d: String, + pub e: ReallyFlags, + } + pub type IntTypedef = i32; + pub type TupleTypedef2 = (IntTypedef,); + #[::tauri_bindgen_host::async_trait] + pub trait Records: Sized { + async fn tuple_arg(&self, x: (char, u32)); + async fn tuple_result(&self) -> (char, u32); + async fn empty_arg(&self, x: Empty); + async fn empty_result(&self) -> Empty; + async fn scalar_arg(&self, x: Scalars); + async fn scalar_result(&self) -> Scalars; + async fn flags_arg(&self, x: ReallyFlags); + async fn flags_result(&self) -> ReallyFlags; + async fn aggregate_arg(&self, x: Aggregates); + async fn aggregate_result(&self) -> Aggregates; + async fn typedef_inout(&self, e: TupleTypedef2) -> i32; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Records + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "tuple_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (char, u32)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.tuple_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "tuple_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.tuple_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "empty_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Empty| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.empty_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "empty_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.empty_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "scalar_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Scalars| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.scalar_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "scalar_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.scalar_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "flags_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ReallyFlags| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.flags_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "flags_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.flags_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "aggregate_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Aggregates| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.aggregate_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "aggregate_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.aggregate_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "records", + "typedef_inout", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: TupleTypedef2| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.typedef_inout(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/resources.rs b/crates/gen-host/tests/async/resources.rs new file mode 100644 index 00000000..296d1f94 --- /dev/null +++ b/crates/gen-host/tests/async/resources.rs @@ -0,0 +1,69 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod resources { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait A { + async fn f1(&self); + async fn f2(&self, a: u32); + async fn f3(&self, a: u32, b: u32); + } + #[::tauri_bindgen_host::async_trait] + pub trait B { + type A: A; + async fn f1(&self) -> ::tauri_bindgen_host::ResourceId; + async fn f2(&self, x: ::tauri_bindgen_host::ResourceId) -> Result; + async fn f3( + &self, + x: Option>, + ) -> Result<::tauri_bindgen_host::ResourceId, ()>; + } + #[::tauri_bindgen_host::async_trait] + pub trait Resources: Sized { + type A: A; + fn get_a_mut(&mut self, id: ::tauri_bindgen_host::ResourceId) -> &mut Self::A; + type B: B; + fn get_b_mut(&mut self, id: ::tauri_bindgen_host::ResourceId) -> &mut Self::B; + async fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; + async fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Resources + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources", + "constructor_a", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.constructor_a().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources", + "constructor_b", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.constructor_b().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/simple-functions.rs b/crates/gen-host/tests/async/simple-functions.rs new file mode 100644 index 00000000..7c65d595 --- /dev/null +++ b/crates/gen-host/tests/async/simple-functions.rs @@ -0,0 +1,111 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod simple_functions { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait SimpleFunctions: Sized { + async fn f1(&self); + async fn f2(&self, a: u32); + async fn f3(&self, a: u32, b: u32); + async fn f4(&self) -> u32; + async fn f5(&self) -> (u32, u32); + async fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: SimpleFunctions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f1", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f1().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u32| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f2(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f3", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u32, u32)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f3(p.0, p.1).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f4", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f4().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f5", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f5().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_functions", + "f6", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u32, u32, u32)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.f6(p.0, p.1, p.2).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/simple-lists.rs b/crates/gen-host/tests/async/simple-lists.rs new file mode 100644 index 00000000..853d33e5 --- /dev/null +++ b/crates/gen-host/tests/async/simple-lists.rs @@ -0,0 +1,83 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod simple_lists { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait SimpleLists: Sized { + async fn simple_list1(&self, l: Vec); + async fn simple_list2(&self) -> Vec; + async fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); + async fn simple_list4(&self, l: Vec>) -> Vec>; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: SimpleLists + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_lists", + "simple_list1", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.simple_list1(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_lists", + "simple_list2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.simple_list2().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_lists", + "simple_list3", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (Vec, Vec)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.simple_list3(p.0, p.1).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "simple_lists", + "simple_list4", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec>| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.simple_list4(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/small-anonymous.rs b/crates/gen-host/tests/async/small-anonymous.rs new file mode 100644 index 00000000..2b04c099 --- /dev/null +++ b/crates/gen-host/tests/async/small-anonymous.rs @@ -0,0 +1,41 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod small_anonymous { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Error { + Success, + Failure, + } + #[::tauri_bindgen_host::async_trait] + pub trait SmallAnonymous: Sized { + async fn option_test(&self) -> Result, Error>; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: SmallAnonymous + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "small_anonymous", + "option_test", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.option_test().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/strings.rs b/crates/gen-host/tests/async/strings.rs new file mode 100644 index 00000000..994c34fd --- /dev/null +++ b/crates/gen-host/tests/async/strings.rs @@ -0,0 +1,66 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod strings { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] + pub trait Strings: Sized { + async fn a(&self, x: String); + async fn b(&self) -> String; + async fn c(&self, a: String, b: String) -> String; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Strings + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "strings", + "a", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: String| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "strings", + "b", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.b().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "strings", + "c", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (String, String)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.c(p.0, p.1).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/unions.rs b/crates/gen-host/tests/async/unions.rs new file mode 100644 index 00000000..d67fe476 --- /dev/null +++ b/crates/gen-host/tests/async/unions.rs @@ -0,0 +1,238 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod unions { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + ///A union of all of the integral types + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum AllIntegers { + /**Bool is equivalent to a 1 bit integer +and is treated that way in some languages*/ + Bool(bool), + U8(u8), + U16(u16), + U32(u32), + U64(u64), + I8(i8), + I16(i16), + S32(i32), + S64(i64), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum AllFloats { + F32(f32), + F64(f64), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum AllText { + Char(char), + String(String), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum DuplicatedS32 { + ///The first s32 + S320(i32), + ///The second s32 + S321(i32), + ///The third s32 + S322(i32), + } + ///A type containing numeric types that are distinct in most languages + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum DistinguishableNum { + ///A Floating Point Number + F64(f64), + ///A Signed Integer + S64(i64), + } + #[::tauri_bindgen_host::async_trait] + pub trait Unions: Sized { + async fn add_one_integer(&self, num: AllIntegers) -> AllIntegers; + async fn add_one_float(&self, num: AllFloats) -> AllFloats; + async fn replace_first_char(&self, text: AllText, letter: char) -> AllText; + async fn identify_integer(&self, num: AllIntegers) -> u8; + async fn identify_float(&self, num: AllFloats) -> u8; + async fn identify_text(&self, text: AllText) -> u8; + async fn add_one_duplicated(&self, num: DuplicatedS32) -> DuplicatedS32; + async fn identify_duplicated(&self, num: DuplicatedS32) -> u8; + async fn add_one_distinguishable_num( + &self, + num: DistinguishableNum, + ) -> DistinguishableNum; + async fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Unions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "add_one_integer", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllIntegers| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.add_one_integer(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "add_one_float", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllFloats| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.add_one_float(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "replace_first_char", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (AllText, char)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.replace_first_char(p.0, p.1).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "identify_integer", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllIntegers| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.identify_integer(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "identify_float", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllFloats| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.identify_float(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "identify_text", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: AllText| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.identify_text(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "add_one_duplicated", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DuplicatedS32| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.add_one_duplicated(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "identify_duplicated", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DuplicatedS32| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.identify_duplicated(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "add_one_distinguishable_num", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DistinguishableNum| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.add_one_distinguishable_num(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "unions", + "identify_distinguishable_num", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DistinguishableNum| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.identify_distinguishable_num(p).await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/async/variants.rs b/crates/gen-host/tests/async/variants.rs new file mode 100644 index 00000000..4737eddb --- /dev/null +++ b/crates/gen-host/tests/async/variants.rs @@ -0,0 +1,497 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod variants { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum E1 { + A, + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum U1 { + U32(u32), + F32(f32), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct Empty {} + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum V1 { + A, + B(U1), + C(E1), + D(String), + E(Empty), + F, + G(u32), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts1 { + A(i32), + B(f32), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts2 { + A(f64), + B(f32), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts3 { + A(f64), + B(u64), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts4 { + A(u32), + B(i64), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts5 { + A(f32), + B(i64), + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum Casts6 { + A((f32, u32)), + B((u32, u32)), + } + #[derive(serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub enum MyErrno { + Bad1, + Bad2, + } + #[derive(serde::Deserialize, serde::Serialize)] + #[derive(Debug, Clone, PartialEq)] + pub struct IsClone { + pub v1: V1, + } + #[::tauri_bindgen_host::async_trait] + pub trait Variants: Sized { + async fn e1_arg(&self, x: E1); + async fn e1_result(&self) -> E1; + async fn u1_arg(&self, x: U1); + async fn u1_result(&self) -> U1; + async fn v1_arg(&self, x: V1); + async fn v1_result(&self) -> V1; + async fn bool_arg(&self, x: bool); + async fn bool_result(&self) -> bool; + async fn option_arg( + &self, + a: Option, + b: Option<()>, + c: Option, + d: Option, + e: Option, + f: Option, + g: Option>, + ); + async fn option_result( + &self, + ) -> ( + Option, + Option<()>, + Option, + Option, + Option, + Option, + Option>, + ); + async fn casts( + &self, + a: Casts1, + b: Casts2, + c: Casts3, + d: Casts4, + e: Casts5, + f: Casts6, + ) -> (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6); + async fn result_arg( + &self, + a: Result<(), ()>, + b: Result<(), E1>, + c: Result, + d: Result<(), ()>, + e: Result, + f: Result>, + ); + async fn result_result( + &self, + ) -> ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result>, + ); + async fn return_result_sugar(&self) -> Result; + async fn return_result_sugar2(&self) -> Result<(), MyErrno>; + async fn return_result_sugar3(&self) -> Result; + async fn return_result_sugar4(&self) -> Result<(i32, u32), MyErrno>; + async fn return_option_sugar(&self) -> Option; + async fn return_option_sugar2(&self) -> Option; + async fn result_simple(&self) -> Result; + async fn is_clone_arg(&self, a: IsClone); + async fn is_clone_return(&self) -> IsClone; + async fn return_named_option(&self) -> Option; + async fn return_named_result(&self) -> Result; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Variants + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "e1_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: E1| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.e1_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "e1_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.e1_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "u1_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: U1| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.u1_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "u1_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.u1_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "v1_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: V1| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.v1_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "v1_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.v1_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "bool_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: bool| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.bool_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "bool_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.bool_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "option_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + Option, + Option<()>, + Option, + Option, + Option, + Option, + Option>, + )| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.option_arg(p.0, p.1, p.2, p.3, p.4, p.5, p.6).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "option_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.option_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "casts", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.casts(p.0, p.1, p.2, p.3, p.4, p.5).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "result_arg", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + Result<(), ()>, + Result<(), E1>, + Result, + Result<(), ()>, + Result, + Result>, + )| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.result_arg(p.0, p.1, p.2, p.3, p.4, p.5).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "result_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.result_result().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_result_sugar", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_result_sugar().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_result_sugar2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_result_sugar2().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_result_sugar3", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_result_sugar3().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_result_sugar4", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_result_sugar4().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_option_sugar", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_option_sugar().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_option_sugar2", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_option_sugar2().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "result_simple", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.result_simple().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "is_clone_arg", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: IsClone| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.is_clone_arg(p).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "is_clone_return", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.is_clone_return().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_named_option", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_named_option().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "variants", + "return_named_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.return_named_result().await) + }) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/codegen-async.rs b/crates/gen-host/tests/codegen-async.rs new file mode 100644 index 00000000..2f797e82 --- /dev/null +++ b/crates/gen-host/tests/codegen-async.rs @@ -0,0 +1,272 @@ +#![allow(clippy::all, unused)] +use pretty_assertions::assert_eq; +use std::path::{Path, PathBuf}; +use tauri_bindgen_core::{Generate, GeneratorBuilder}; +use tauri_bindgen_gen_host::Builder; + +fn gen_interface( + opts: Builder, + _name: impl AsRef, + input: impl AsRef, +) -> (String, String) { + let iface = wit_parser::parse_and_resolve_str(&input, |_| false).unwrap(); + + let mut gen = opts.build(iface); + let (filename, contents) = gen.to_file(); + + (filename.to_str().unwrap().to_string(), contents) +} + +#[test] +fn chars() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface(opts, "chars", include_str!("../../../wit/chars.wit")); + + assert_eq!(filename, "chars.rs"); + assert_eq!(contents, include_str!("./async/chars.rs")); +} + +#[test] +fn convention() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "conventions", + include_str!("../../../wit/conventions.wit"), + ); + + assert_eq!(filename, "conventions.rs"); + assert_eq!(contents, include_str!("./async/conventions.rs")); +} + +#[test] +fn empty() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface(opts, "empty", include_str!("../../../wit/empty.wit")); + + assert_eq!(filename, "empty.rs"); + assert_eq!(contents, include_str!("./async/empty.rs")); +} + +#[test] +fn flags() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface(opts, "flegs", include_str!("../../../wit/flags.wit")); + + assert_eq!(filename, "flegs.rs"); + assert_eq!(contents, include_str!("./async/flegs.rs")); +} + +#[test] +fn floats() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "floats", include_str!("../../../wit/floats.wit")); + + assert_eq!(filename, "floats.rs"); + assert_eq!(contents, include_str!("./async/floats.rs")); +} + +#[test] +fn integers() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "integers", include_str!("../../../wit/integers.wit")); + + assert_eq!(filename, "integers.rs"); + assert_eq!(contents, include_str!("./async/integers.rs")); +} + +#[test] +fn lists() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface(opts, "lists", include_str!("../../../wit/lists.wit")); + + assert_eq!(filename, "lists.rs"); + assert_eq!(contents, include_str!("./async/lists.rs")); +} + +#[test] +fn many_arguments() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "many-arguments", + include_str!("../../../wit/many_arguments.wit"), + ); + + assert_eq!(filename, "many-arguments.rs"); + assert_eq!(contents, include_str!("./async/many-arguments.rs")); +} + +#[test] +fn multi_return() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "multi-return", + include_str!("../../../wit/multi_return.wit"), + ); + + assert_eq!(filename, "multi-return.rs"); + assert_eq!(contents, include_str!("./async/multi-return.rs")); +} + +#[test] +fn records() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "records", include_str!("../../../wit/records.wit")); + + assert_eq!(filename, "records.rs"); + assert_eq!(contents, include_str!("./async/records.rs")); +} + +#[test] +fn simple_functions() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "simple-functions", + include_str!("../../../wit/simple_functions.wit"), + ); + + assert_eq!(filename, "simple-functions.rs"); + assert_eq!(contents, include_str!("./async/simple-functions.rs")); +} + +#[test] +fn simple_lists() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "simple-lists", + include_str!("../../../wit/simple_lists.wit"), + ); + + assert_eq!(filename, "simple-lists.rs"); + assert_eq!(contents, include_str!("./async/simple-lists.rs")); +} + +#[test] +fn small_anonymous() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = gen_interface( + opts, + "small-anonymous", + include_str!("../../../wit/small_anonymous.wit"), + ); + + assert_eq!(filename, "small-anonymous.rs"); + assert_eq!(contents, include_str!("./async/small-anonymous.rs")); +} + +#[test] +fn strings() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "strings", include_str!("../../../wit/strings.wit")); + + assert_eq!(filename, "strings.rs"); + assert_eq!(contents, include_str!("./async/strings.rs")); +} + +#[test] +fn unions() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "unions", include_str!("../../../wit/unions.wit")); + + assert_eq!(filename, "unions.rs"); + assert_eq!(contents, include_str!("./async/unions.rs")); +} + +#[test] +fn variants() { + let opts = Builder { + fmt: true, + tracing: true, + async_: true, + }; + + let (filename, contents) = + gen_interface(opts, "variants", include_str!("../../../wit/variants.wit")); + + assert_eq!(filename, "variants.rs"); + assert_eq!(contents, include_str!("./async/variants.rs")); +} diff --git a/crates/gen-host/tests/codegen.rs b/crates/gen-host/tests/codegen-sync.rs similarity index 83% rename from crates/gen-host/tests/codegen.rs rename to crates/gen-host/tests/codegen-sync.rs index 580baf1a..e047b72b 100644 --- a/crates/gen-host/tests/codegen.rs +++ b/crates/gen-host/tests/codegen-sync.rs @@ -28,7 +28,7 @@ fn chars() { let (filename, contents) = gen_interface(opts, "chars", include_str!("../../../wit/chars.wit")); assert_eq!(filename, "chars.rs"); - assert_eq!(contents, include_str!("./chars.rs")); + assert_eq!(contents, include_str!("./sync/chars.rs")); } #[test] @@ -46,7 +46,7 @@ fn convention() { ); assert_eq!(filename, "conventions.rs"); - assert_eq!(contents, include_str!("./conventions.rs")); + assert_eq!(contents, include_str!("./sync/conventions.rs")); } #[test] @@ -60,7 +60,7 @@ fn empty() { let (filename, contents) = gen_interface(opts, "empty", include_str!("../../../wit/empty.wit")); assert_eq!(filename, "empty.rs"); - assert_eq!(contents, include_str!("./empty.rs")); + assert_eq!(contents, include_str!("./sync/empty.rs")); } #[test] @@ -74,7 +74,7 @@ fn flags() { let (filename, contents) = gen_interface(opts, "flegs", include_str!("../../../wit/flags.wit")); assert_eq!(filename, "flegs.rs"); - assert_eq!(contents, include_str!("./flegs.rs")); + assert_eq!(contents, include_str!("./sync/flegs.rs")); } #[test] @@ -89,7 +89,7 @@ fn floats() { gen_interface(opts, "floats", include_str!("../../../wit/floats.wit")); assert_eq!(filename, "floats.rs"); - assert_eq!(contents, include_str!("./floats.rs")); + assert_eq!(contents, include_str!("./sync/floats.rs")); } #[test] @@ -104,7 +104,7 @@ fn integers() { gen_interface(opts, "integers", include_str!("../../../wit/integers.wit")); assert_eq!(filename, "integers.rs"); - assert_eq!(contents, include_str!("./integers.rs")); + assert_eq!(contents, include_str!("./sync/integers.rs")); } #[test] @@ -118,7 +118,7 @@ fn lists() { let (filename, contents) = gen_interface(opts, "lists", include_str!("../../../wit/lists.wit")); assert_eq!(filename, "lists.rs"); - assert_eq!(contents, include_str!("./lists.rs")); + assert_eq!(contents, include_str!("./sync/lists.rs")); } #[test] @@ -136,7 +136,7 @@ fn many_arguments() { ); assert_eq!(filename, "many-arguments.rs"); - assert_eq!(contents, include_str!("./many-arguments.rs")); + assert_eq!(contents, include_str!("./sync/many-arguments.rs")); } #[test] @@ -154,7 +154,7 @@ fn multi_return() { ); assert_eq!(filename, "multi-return.rs"); - assert_eq!(contents, include_str!("./multi-return.rs")); + assert_eq!(contents, include_str!("./sync/multi-return.rs")); } #[test] @@ -169,7 +169,7 @@ fn records() { gen_interface(opts, "records", include_str!("../../../wit/records.wit")); assert_eq!(filename, "records.rs"); - assert_eq!(contents, include_str!("./records.rs")); + assert_eq!(contents, include_str!("./sync/records.rs")); } #[test] @@ -187,7 +187,7 @@ fn simple_functions() { ); assert_eq!(filename, "simple-functions.rs"); - assert_eq!(contents, include_str!("./simple-functions.rs")); + assert_eq!(contents, include_str!("./sync/simple-functions.rs")); } #[test] @@ -205,7 +205,7 @@ fn simple_lists() { ); assert_eq!(filename, "simple-lists.rs"); - assert_eq!(contents, include_str!("./simple-lists.rs")); + assert_eq!(contents, include_str!("./sync/simple-lists.rs")); } #[test] @@ -223,7 +223,7 @@ fn small_anonymous() { ); assert_eq!(filename, "small-anonymous.rs"); - assert_eq!(contents, include_str!("./small-anonymous.rs")); + assert_eq!(contents, include_str!("./sync/small-anonymous.rs")); } #[test] @@ -238,7 +238,7 @@ fn strings() { gen_interface(opts, "strings", include_str!("../../../wit/strings.wit")); assert_eq!(filename, "strings.rs"); - assert_eq!(contents, include_str!("./strings.rs")); + assert_eq!(contents, include_str!("./sync/strings.rs")); } #[test] @@ -253,7 +253,7 @@ fn unions() { gen_interface(opts, "unions", include_str!("../../../wit/unions.wit")); assert_eq!(filename, "unions.rs"); - assert_eq!(contents, include_str!("./unions.rs")); + assert_eq!(contents, include_str!("./sync/unions.rs")); } #[test] @@ -268,5 +268,5 @@ fn variants() { gen_interface(opts, "variants", include_str!("../../../wit/variants.wit")); assert_eq!(filename, "variants.rs"); - assert_eq!(contents, include_str!("./variants.rs")); + assert_eq!(contents, include_str!("./sync/variants.rs")); } diff --git a/crates/gen-host/tests/strings.rs b/crates/gen-host/tests/strings.rs index 347eda34..c929e1ca 100644 --- a/crates/gen-host/tests/strings.rs +++ b/crates/gen-host/tests/strings.rs @@ -3,56 +3,61 @@ pub mod strings { use ::tauri_bindgen_host::serde; use ::tauri_bindgen_host::bitflags; + #[::tauri_bindgen_host::async_trait] pub trait Strings: Sized { - fn a(&self, x: String); - fn b(&self) -> String; - fn c(&self, a: String, b: String) -> String; + async fn a(&self, x: String); + async fn b(&self) -> String; + async fn c(&self, a: String, b: String) -> String; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Strings + Send + Sync + 'static, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define_async( "strings", "a", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: String, - | -> ::tauri_bindgen_host::anyhow::Result<()> { - let ctx = get_cx(ctx.data()); - Ok(ctx.a(x)) + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: String| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.a(p).await) + }) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define_async( "strings", "b", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { - let ctx = get_cx(ctx.data()); - Ok(ctx.b()) + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.b().await) + }) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define_async( "strings", "c", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: String, - b: String, - | -> ::tauri_bindgen_host::anyhow::Result { - let ctx = get_cx(ctx.data()); - Ok(ctx.c(a, b)) + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (String, String)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + Ok(ctx.c(p.0, p.1).await) + }) }, )?; Ok(()) diff --git a/crates/gen-host/tests/chars.rs b/crates/gen-host/tests/sync/chars.rs similarity index 69% rename from crates/gen-host/tests/chars.rs rename to crates/gen-host/tests/sync/chars.rs index 5f9a0d36..409faa6b 100644 --- a/crates/gen-host/tests/chars.rs +++ b/crates/gen-host/tests/sync/chars.rs @@ -9,35 +9,32 @@ pub mod chars { ///A function that returns a character fn return_char(&self) -> char; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Chars + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "chars", "take_char", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: char, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: char| { let ctx = get_cx(ctx.data()); - Ok(ctx.take_char(x)) + Ok(ctx.take_char(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "chars", "return_char", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_char()) }, diff --git a/crates/gen-host/tests/conventions.rs b/crates/gen-host/tests/sync/conventions.rs similarity index 65% rename from crates/gen-host/tests/conventions.rs rename to crates/gen-host/tests/sync/conventions.rs index da1f2e7e..f771b498 100644 --- a/crates/gen-host/tests/conventions.rs +++ b/crates/gen-host/tests/sync/conventions.rs @@ -23,155 +23,135 @@ pub mod conventions { fn explicit_snake(&self); fn bool(&self); } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Conventions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "kebab_case", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.kebab_case()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "foo", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: LudicrousSpeed, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: LudicrousSpeed| + { let ctx = get_cx(ctx.data()); - Ok(ctx.foo(x)) + Ok(ctx.foo(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "function_with_underscores", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_underscores()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "function_with_no_weird_characters", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_no_weird_characters()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "apple", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.apple()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "apple_pear", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "apple_pear_grape", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear_grape()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "a0", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.a0()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "is_xml", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.is_xml()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "explicit", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.explicit()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "explicit_snake", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.explicit_snake()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "conventions", "bool", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.bool()) }, diff --git a/crates/gen-host/tests/empty.rs b/crates/gen-host/tests/sync/empty.rs similarity index 81% rename from crates/gen-host/tests/empty.rs rename to crates/gen-host/tests/sync/empty.rs index d1447513..df22c4db 100644 --- a/crates/gen-host/tests/empty.rs +++ b/crates/gen-host/tests/sync/empty.rs @@ -4,12 +4,14 @@ pub mod empty { use ::tauri_bindgen_host::serde; use ::tauri_bindgen_host::bitflags; pub trait Empty: Sized {} - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Empty + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); Ok(()) diff --git a/crates/gen-host/tests/flegs.rs b/crates/gen-host/tests/sync/flegs.rs similarity index 75% rename from crates/gen-host/tests/flegs.rs rename to crates/gen-host/tests/sync/flegs.rs index 510eab8f..2e02e01c 100644 --- a/crates/gen-host/tests/flegs.rs +++ b/crates/gen-host/tests/sync/flegs.rs @@ -67,103 +67,84 @@ pub mod flegs { fn roundtrip_flag32(&self, x: Flag32) -> Flag32; fn roundtrip_flag64(&self, x: Flag64) -> Flag64; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Flegs + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag1", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag1, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag1| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag1(x)) + Ok(ctx.roundtrip_flag1(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag2, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag2| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag2(x)) + Ok(ctx.roundtrip_flag2(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag4", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag4, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag4| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag4(x)) + Ok(ctx.roundtrip_flag4(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag8", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag8, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag8| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag8(x)) + Ok(ctx.roundtrip_flag8(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag16", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag16, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag16| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag16(x)) + Ok(ctx.roundtrip_flag16(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag32", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag32, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag32| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag32(x)) + Ok(ctx.roundtrip_flag32(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "flegs", "roundtrip_flag64", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Flag64, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Flag64| { let ctx = get_cx(ctx.data()); - Ok(ctx.roundtrip_flag64(x)) + Ok(ctx.roundtrip_flag64(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/floats.rs b/crates/gen-host/tests/sync/floats.rs similarity index 63% rename from crates/gen-host/tests/floats.rs rename to crates/gen-host/tests/sync/floats.rs index 2434a022..aa50984e 100644 --- a/crates/gen-host/tests/floats.rs +++ b/crates/gen-host/tests/sync/floats.rs @@ -9,60 +9,52 @@ pub mod floats { fn float32_result(&self) -> f32; fn float64_result(&self) -> f64; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Floats + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "floats", "float32_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: f32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: f32| { let ctx = get_cx(ctx.data()); - Ok(ctx.float32_param(x)) + Ok(ctx.float32_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "floats", "float64_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: f64, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: f64| { let ctx = get_cx(ctx.data()); - Ok(ctx.float64_param(x)) + Ok(ctx.float64_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "floats", "float32_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.float32_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "floats", "float64_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.float64_result()) }, diff --git a/crates/gen-host/tests/integers.rs b/crates/gen-host/tests/sync/integers.rs similarity index 56% rename from crates/gen-host/tests/integers.rs rename to crates/gen-host/tests/sync/integers.rs index 07c6d598..499babc2 100644 --- a/crates/gen-host/tests/integers.rs +++ b/crates/gen-host/tests/sync/integers.rs @@ -39,294 +39,235 @@ pub mod integers { fn r10(&self) -> i128; fn pair_ret(&self) -> (i64, u8); } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Integers + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a1", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: u8, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u8| { let ctx = get_cx(ctx.data()); - Ok(ctx.a1(x)) + Ok(ctx.a1(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: i8, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i8| { let ctx = get_cx(ctx.data()); - Ok(ctx.a2(x)) + Ok(ctx.a2(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a3", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: u16, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u16| { let ctx = get_cx(ctx.data()); - Ok(ctx.a3(x)) + Ok(ctx.a3(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a4", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: i16, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i16| { let ctx = get_cx(ctx.data()); - Ok(ctx.a4(x)) + Ok(ctx.a4(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a5", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: u32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u32| { let ctx = get_cx(ctx.data()); - Ok(ctx.a5(x)) + Ok(ctx.a5(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a6", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: i32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i32| { let ctx = get_cx(ctx.data()); - Ok(ctx.a6(x)) + Ok(ctx.a6(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a7", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: u64, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u64| { let ctx = get_cx(ctx.data()); - Ok(ctx.a7(x)) + Ok(ctx.a7(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a8", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: i64, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i64| { let ctx = get_cx(ctx.data()); - Ok(ctx.a8(x)) + Ok(ctx.a8(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a9", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: u128, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u128| { let ctx = get_cx(ctx.data()); - Ok(ctx.a9(x)) + Ok(ctx.a9(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a10", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: i128, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: i128| { let ctx = get_cx(ctx.data()); - Ok(ctx.a10(x)) + Ok(ctx.a10(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "a11", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - p1: u8, - p2: i8, - p3: u16, - p4: i16, - p5: u32, - p6: i32, - p7: u64, - p8: i64, - p9: u128, - p10: i128, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.a11(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)) + Ok(ctx.a11(p.0, p.1, p.2, p.3, p.4, p.5, p.6, p.7, p.8, p.9)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r1", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r1()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r2()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r3", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r3()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r4", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r4()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r5", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r5()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r6", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r6()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r7", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r7()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r8", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r8()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r9", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r9()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "r10", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.r10()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "integers", "pair_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<(i64, u8)> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.pair_ret()) }, diff --git a/crates/gen-host/tests/lists.rs b/crates/gen-host/tests/sync/lists.rs similarity index 62% rename from crates/gen-host/tests/lists.rs rename to crates/gen-host/tests/sync/lists.rs index 3efc0797..1b87547f 100644 --- a/crates/gen-host/tests/lists.rs +++ b/crates/gen-host/tests/sync/lists.rs @@ -77,428 +77,374 @@ pub mod lists { fn variant_list(&self, x: Vec) -> Vec; fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Lists + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u8_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_u8_param(x)) + Ok(ctx.list_u8_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u16_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_u16_param(x)) + Ok(ctx.list_u16_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u32_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_u32_param(x)) + Ok(ctx.list_u32_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u64_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_u64_param(x)) + Ok(ctx.list_u64_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.list_u128_param(x)) + Ok(ctx.list_u128_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s8_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_s8_param(x)) + Ok(ctx.list_s8_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s16_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_s16_param(x)) + Ok(ctx.list_s16_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s32_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_s32_param(x)) + Ok(ctx.list_s32_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s64_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_s64_param(x)) + Ok(ctx.list_s64_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.list_s128_param(x)) + Ok(ctx.list_s128_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_float32_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_float32_param(x)) + Ok(ctx.list_float32_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_float64_param", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.list_float64_param(x)) + Ok(ctx.list_float64_param(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u8_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_u8_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u16_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_u16_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u32_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_u32_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u64_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_u64_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_u128_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_u128_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s8_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_s8_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s16_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_s16_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s32_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_s32_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s64_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_s64_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_s128_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_s128_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_float32_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_float32_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "list_float64_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.list_float64_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "tuple_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec<(u8, i8)>, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec<(u8, i8)>| + { let ctx = get_cx(ctx.data()); - Ok(ctx.tuple_list(x)) + Ok(ctx.tuple_list(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "string_list_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.string_list_arg(a)) + Ok(ctx.string_list_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "string_list_ret", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.string_list_ret()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "tuple_string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec<(u8, String)>, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec<(u8, String)>| + { let ctx = get_cx(ctx.data()); - Ok(ctx.tuple_string_list(x)) + Ok(ctx.tuple_string_list(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.string_list(x)) + Ok(ctx.string_list(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "record_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.record_list(x)) + Ok(ctx.record_list(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "record_list_reverse", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.record_list_reverse(x)) + Ok(ctx.record_list_reverse(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "variant_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Vec, - | -> ::tauri_bindgen_host::anyhow::Result> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec| + { let ctx = get_cx(ctx.data()); - Ok(ctx.variant_list(x)) + Ok(ctx.variant_list(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "lists", "load_store_everything", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: LoadStoreAllSizes, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: LoadStoreAllSizes| + { let ctx = get_cx(ctx.data()); - Ok(ctx.load_store_everything(a)) + Ok(ctx.load_store_everything(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/many-arguments.rs b/crates/gen-host/tests/sync/many-arguments.rs similarity index 62% rename from crates/gen-host/tests/many-arguments.rs rename to crates/gen-host/tests/sync/many-arguments.rs index 6077eb78..802cfec5 100644 --- a/crates/gen-host/tests/many-arguments.rs +++ b/crates/gen-host/tests/sync/many-arguments.rs @@ -49,73 +49,77 @@ pub mod many_arguments { ); fn big_argument(&self, x: BigStruct); } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: ManyArguments + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "many_arguments", "many_args", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a1: u64, - a2: u64, - a3: u64, - a4: u64, - a5: u64, - a6: u64, - a7: u64, - a8: u64, - a9: u64, - a10: u64, - a11: u64, - a12: u64, - a13: u64, - a14: u64, - a15: u64, - a16: u64, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + )| + { let ctx = get_cx(ctx.data()); Ok( ctx .many_args( - a1, - a2, - a3, - a4, - a5, - a6, - a7, - a8, - a9, - a10, - a11, - a12, - a13, - a14, - a15, - a16, + p.0, + p.1, + p.2, + p.3, + p.4, + p.5, + p.6, + p.7, + p.8, + p.9, + p.10, + p.11, + p.12, + p.13, + p.14, + p.15, ), ) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "many_arguments", "big_argument", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: BigStruct, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: BigStruct| + { let ctx = get_cx(ctx.data()); - Ok(ctx.big_argument(x)) + Ok(ctx.big_argument(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/multi-return.rs b/crates/gen-host/tests/sync/multi-return.rs similarity index 65% rename from crates/gen-host/tests/multi-return.rs rename to crates/gen-host/tests/sync/multi-return.rs index 37ae0a55..b3b82870 100644 --- a/crates/gen-host/tests/multi-return.rs +++ b/crates/gen-host/tests/sync/multi-return.rs @@ -10,70 +10,62 @@ pub mod multi_return { fn mrd(&self) -> u32; fn mre(&self) -> (u32, f32); } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: MultiReturn + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "multi_return", "mra", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.mra()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "multi_return", "mrb", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.mrb()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "multi_return", "mrc", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.mrc()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "multi_return", "mrd", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.mrd()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "multi_return", "mre", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<(u32, f32)> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.mre()) }, diff --git a/crates/gen-host/tests/records.rs b/crates/gen-host/tests/sync/records.rs similarity index 69% rename from crates/gen-host/tests/records.rs rename to crates/gen-host/tests/sync/records.rs index b04eb93a..02df4bd3 100644 --- a/crates/gen-host/tests/records.rs +++ b/crates/gen-host/tests/sync/records.rs @@ -55,150 +55,136 @@ All of the fields are bool*/ fn aggregate_result(&self) -> Aggregates; fn typedef_inout(&self, e: TupleTypedef2) -> i32; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Records + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "tuple_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: (char, u32), - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (char, u32)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.tuple_arg(x)) + Ok(ctx.tuple_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "tuple_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<(char, u32)> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.tuple_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "empty_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Empty, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Empty| { let ctx = get_cx(ctx.data()); - Ok(ctx.empty_arg(x)) + Ok(ctx.empty_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "empty_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.empty_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "scalar_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Scalars, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Scalars| { let ctx = get_cx(ctx.data()); - Ok(ctx.scalar_arg(x)) + Ok(ctx.scalar_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "scalar_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.scalar_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "flags_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: ReallyFlags, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ReallyFlags| + { let ctx = get_cx(ctx.data()); - Ok(ctx.flags_arg(x)) + Ok(ctx.flags_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "flags_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.flags_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "aggregate_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: Aggregates, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Aggregates| + { let ctx = get_cx(ctx.data()); - Ok(ctx.aggregate_arg(x)) + Ok(ctx.aggregate_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "aggregate_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.aggregate_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "records", "typedef_inout", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - e: TupleTypedef2, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: TupleTypedef2| + { let ctx = get_cx(ctx.data()); - Ok(ctx.typedef_inout(e)) + Ok(ctx.typedef_inout(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/resources.rs b/crates/gen-host/tests/sync/resources.rs similarity index 76% rename from crates/gen-host/tests/resources.rs rename to crates/gen-host/tests/sync/resources.rs index d443caae..dd8e461d 100644 --- a/crates/gen-host/tests/resources.rs +++ b/crates/gen-host/tests/sync/resources.rs @@ -25,38 +25,32 @@ pub mod resources { fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Resources + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources", "constructor_a", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result< - ::tauri_bindgen_host::ResourceId, - > { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.constructor_a()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources", "constructor_b", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result< - ::tauri_bindgen_host::ResourceId, - > { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.constructor_b()) }, diff --git a/crates/gen-host/tests/simple-functions.rs b/crates/gen-host/tests/sync/simple-functions.rs similarity index 64% rename from crates/gen-host/tests/simple-functions.rs rename to crates/gen-host/tests/sync/simple-functions.rs index d3683d6b..4fd9cae5 100644 --- a/crates/gen-host/tests/simple-functions.rs +++ b/crates/gen-host/tests/sync/simple-functions.rs @@ -11,90 +11,80 @@ pub mod simple_functions { fn f5(&self) -> (u32, u32); fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: SimpleFunctions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f1", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.f1()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: u32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: u32| { let ctx = get_cx(ctx.data()); - Ok(ctx.f2(a)) + Ok(ctx.f2(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: u32, - b: u32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u32, u32)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.f3(a, b)) + Ok(ctx.f3(p.0, p.1)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f4", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.f4()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f5", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result<(u32, u32)> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.f5()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_functions", "f6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: u32, - b: u32, - c: u32, - | -> ::tauri_bindgen_host::anyhow::Result<(u32, u32, u32)> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (u32, u32, u32)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.f6(a, b, c)) + Ok(ctx.f6(p.0, p.1, p.2)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/simple-lists.rs b/crates/gen-host/tests/sync/simple-lists.rs similarity index 66% rename from crates/gen-host/tests/simple-lists.rs rename to crates/gen-host/tests/sync/simple-lists.rs index 9bbc7c4d..3fa552ed 100644 --- a/crates/gen-host/tests/simple-lists.rs +++ b/crates/gen-host/tests/sync/simple-lists.rs @@ -9,64 +9,60 @@ pub mod simple_lists { fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); fn simple_list4(&self, l: Vec>) -> Vec>; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: SimpleLists + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_lists", "simple_list1", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - l: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: Vec| { let ctx = get_cx(ctx.data()); - Ok(ctx.simple_list1(l)) + Ok(ctx.simple_list1(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_lists", "simple_list2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.simple_list2()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_lists", "simple_list3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: Vec, - b: Vec, - | -> ::tauri_bindgen_host::anyhow::Result<(Vec, Vec)> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (Vec, Vec)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.simple_list3(a, b)) + Ok(ctx.simple_list3(p.0, p.1)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "simple_lists", "simple_list4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - l: Vec>, - | -> ::tauri_bindgen_host::anyhow::Result>> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: Vec>| + { let ctx = get_cx(ctx.data()); - Ok(ctx.simple_list4(l)) + Ok(ctx.simple_list4(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/small-anonymous.rs b/crates/gen-host/tests/sync/small-anonymous.rs similarity index 78% rename from crates/gen-host/tests/small-anonymous.rs rename to crates/gen-host/tests/sync/small-anonymous.rs index e8a94526..6cce9ef1 100644 --- a/crates/gen-host/tests/small-anonymous.rs +++ b/crates/gen-host/tests/sync/small-anonymous.rs @@ -12,22 +12,22 @@ pub mod small_anonymous { pub trait SmallAnonymous: Sized { fn option_test(&self) -> Result, Error>; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: SmallAnonymous + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "small_anonymous", "option_test", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result, Error>> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.option_test()) }, diff --git a/crates/gen-host/tests/sync/strings.rs b/crates/gen-host/tests/sync/strings.rs new file mode 100644 index 00000000..608a33ca --- /dev/null +++ b/crates/gen-host/tests/sync/strings.rs @@ -0,0 +1,56 @@ +#[allow(unused_imports, unused_variables, dead_code)] +#[rustfmt::skip] +pub mod strings { + use ::tauri_bindgen_host::serde; + use ::tauri_bindgen_host::bitflags; + pub trait Strings: Sized { + fn a(&self, x: String); + fn b(&self) -> String; + fn c(&self, a: String, b: String) -> String; + } + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, + ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> + where + T: Send + Sync + 'static, + U: Strings + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, + { + let wrapped_get_cx = ::std::sync::Arc::new(get_cx); + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define( + "strings", + "a", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: String| { + let ctx = get_cx(ctx.data()); + Ok(ctx.a(p)) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define( + "strings", + "b", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { + let ctx = get_cx(ctx.data()); + Ok(ctx.b()) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define( + "strings", + "c", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (String, String)| + { + let ctx = get_cx(ctx.data()); + Ok(ctx.c(p.0, p.1)) + }, + )?; + Ok(()) + } +} diff --git a/crates/gen-host/tests/unions.rs b/crates/gen-host/tests/sync/unions.rs similarity index 72% rename from crates/gen-host/tests/unions.rs rename to crates/gen-host/tests/sync/unions.rs index f040f0b8..f60869be 100644 --- a/crates/gen-host/tests/unions.rs +++ b/crates/gen-host/tests/sync/unions.rs @@ -65,143 +65,141 @@ and is treated that way in some languages*/ ) -> DistinguishableNum; fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Unions + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "add_one_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: AllIntegers, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllIntegers| + { let ctx = get_cx(ctx.data()); - Ok(ctx.add_one_integer(num)) + Ok(ctx.add_one_integer(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "add_one_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: AllFloats, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllFloats| + { let ctx = get_cx(ctx.data()); - Ok(ctx.add_one_float(num)) + Ok(ctx.add_one_float(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "replace_first_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - text: AllText, - letter: char, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (AllText, char)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.replace_first_char(text, letter)) + Ok(ctx.replace_first_char(p.0, p.1)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "identify_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: AllIntegers, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllIntegers| + { let ctx = get_cx(ctx.data()); - Ok(ctx.identify_integer(num)) + Ok(ctx.identify_integer(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "identify_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: AllFloats, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: AllFloats| + { let ctx = get_cx(ctx.data()); - Ok(ctx.identify_float(num)) + Ok(ctx.identify_float(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "identify_text", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - text: AllText, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: AllText| { let ctx = get_cx(ctx.data()); - Ok(ctx.identify_text(text)) + Ok(ctx.identify_text(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "add_one_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: DuplicatedS32, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DuplicatedS32| + { let ctx = get_cx(ctx.data()); - Ok(ctx.add_one_duplicated(num)) + Ok(ctx.add_one_duplicated(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "identify_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: DuplicatedS32, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DuplicatedS32| + { let ctx = get_cx(ctx.data()); - Ok(ctx.identify_duplicated(num)) + Ok(ctx.identify_duplicated(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "add_one_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: DistinguishableNum, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DistinguishableNum| + { let ctx = get_cx(ctx.data()); - Ok(ctx.add_one_distinguishable_num(num)) + Ok(ctx.add_one_distinguishable_num(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "unions", "identify_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - num: DistinguishableNum, - | -> ::tauri_bindgen_host::anyhow::Result { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: DistinguishableNum| + { let ctx = get_cx(ctx.data()); - Ok(ctx.identify_distinguishable_num(num)) + Ok(ctx.identify_distinguishable_num(p)) }, )?; Ok(()) diff --git a/crates/gen-host/tests/variants.rs b/crates/gen-host/tests/sync/variants.rs similarity index 65% rename from crates/gen-host/tests/variants.rs rename to crates/gen-host/tests/sync/variants.rs index e1d4a344..50572a87 100644 --- a/crates/gen-host/tests/variants.rs +++ b/crates/gen-host/tests/sync/variants.rs @@ -145,142 +145,104 @@ pub mod variants { fn return_named_option(&self) -> Option; fn return_named_result(&self) -> Result; } - pub fn add_to_router( + pub fn add_to_router( router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where + T: Send + Sync + 'static, U: Variants + Send + Sync + 'static, + R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "e1_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: E1, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: E1| { let ctx = get_cx(ctx.data()); - Ok(ctx.e1_arg(x)) + Ok(ctx.e1_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "e1_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.e1_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "u1_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: U1, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: U1| { let ctx = get_cx(ctx.data()); - Ok(ctx.u1_arg(x)) + Ok(ctx.u1_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "u1_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.u1_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "v1_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: V1, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: V1| { let ctx = get_cx(ctx.data()); - Ok(ctx.v1_arg(x)) + Ok(ctx.v1_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "v1_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.v1_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "bool_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: bool, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: bool| { let ctx = get_cx(ctx.data()); - Ok(ctx.bool_arg(x)) + Ok(ctx.bool_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "bool_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.bool_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "option_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: Option, - b: Option<()>, - c: Option, - d: Option, - e: Option, - f: Option, - g: Option>, - | -> ::tauri_bindgen_host::anyhow::Result<()> { - let ctx = get_cx(ctx.data()); - Ok(ctx.option_arg(a, b, c, d, e, f, g)) - }, - )?; - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router - .func_wrap( - "variants", - "option_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result< - ( + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( Option, Option<()>, Option, @@ -288,200 +250,171 @@ pub mod variants { Option, Option, Option>, - ), - > { + )| + { let ctx = get_cx(ctx.data()); - Ok(ctx.option_result()) + Ok(ctx.option_arg(p.0, p.1, p.2, p.3, p.4, p.5, p.6)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", - "casts", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: Casts1, - b: Casts2, - c: Casts3, - d: Casts4, - e: Casts5, - f: Casts6, - | -> ::tauri_bindgen_host::anyhow::Result< - (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), - > { + "option_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); - Ok(ctx.casts(a, b, c, d, e, f)) + Ok(ctx.option_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", - "result_arg", + "casts", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: Result<(), ()>, - b: Result<(), E1>, - c: Result, - d: Result<(), ()>, - e: Result, - f: Result>, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.result_arg(a, b, c, d, e, f)) + Ok(ctx.casts(p.0, p.1, p.2, p.3, p.4, p.5)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", - "result_result", + "result_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result< - ( + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( Result<(), ()>, Result<(), E1>, Result, Result<(), ()>, Result, Result>, - ), - > { + )| + { + let ctx = get_cx(ctx.data()); + Ok(ctx.result_arg(p.0, p.1, p.2, p.3, p.4, p.5)) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define( + "variants", + "result_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.result_result()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_result_sugar", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_result_sugar2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar2()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_result_sugar3", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar3()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_result_sugar4", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar4()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_option_sugar", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_option_sugar2", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar2()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "result_simple", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.result_simple()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "is_clone_arg", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: IsClone, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: IsClone| { let ctx = get_cx(ctx.data()); - Ok(ctx.is_clone_arg(a)) + Ok(ctx.is_clone_arg(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "is_clone_return", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.is_clone_return()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_named_option", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_option()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "variants", "return_named_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_result()) }, diff --git a/crates/ipc-router-wip/Cargo.toml b/crates/ipc-router-wip/Cargo.toml index ccf580b9..f6b902d1 100644 --- a/crates/ipc-router-wip/Cargo.toml +++ b/crates/ipc-router-wip/Cargo.toml @@ -14,3 +14,4 @@ log.workspace = true postcard = { version = "1.0.7", features = ["alloc"] } tauri.workspace = true tokio = { version = "1.32.0", features = ["sync", "macros"] } +futures-util = "0.3.28" diff --git a/crates/ipc-router-wip/src/lib.rs b/crates/ipc-router-wip/src/lib.rs index 13253608..b1227cc0 100644 --- a/crates/ipc-router-wip/src/lib.rs +++ b/crates/ipc-router-wip/src/lib.rs @@ -1,44 +1,34 @@ #![allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] pub use anyhow::Error; -use anyhow::{bail, Result}; + +use futures_util::FutureExt; +use serde::{de::DeserializeOwned, Serialize}; use std::{ collections::{hash_map::Entry, HashMap}, + future::Future, + marker::PhantomData, + pin::Pin, sync::Arc, }; -use tauri::{ - http::{header::CONTENT_TYPE, Request, Response, StatusCode}, - AppHandle, Runtime, -}; -use tokio::sync::{ - mpsc, - oneshot::{self, Sender}, -}; +use tauri::http::{header::CONTENT_TYPE, Request, Response, StatusCode}; -#[derive(Default)] -pub struct Router { - data: Arc, - string2idx: HashMap, usize>, - strings: Vec>, - map: HashMap>, -} +type Definition = + Box, &[u8]) -> anyhow::Result + Send + Sync + 'static>; -pub type Definition = - Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; +enum CallResult { + Value(Vec), + Future(Pin>> + Send + 'static>>), +} -pub struct Caller<'a, T, R: Runtime> { - data: &'a T, - app_handle: AppHandle, +pub struct Caller { + data: Arc, } -impl<'a, T, R: Runtime> Caller<'a, T, R> { +impl Caller { #[must_use] pub fn data(&self) -> &T { - self.data - } - #[must_use] - pub fn app_handle(&self) -> &AppHandle { - &self.app_handle + &self.data } } @@ -48,40 +38,84 @@ struct ImportKey { name: usize, } -impl Router { - #[must_use] - pub fn new(data: U) -> Self { +pub struct Router { + data: Arc, + _m: PhantomData, + string2idx: HashMap, usize>, + strings: Vec>, + map: HashMap>, +} + +impl Router { + pub fn new(data: T) -> Self { Self { + data: Arc::new(data), + _m: PhantomData, string2idx: HashMap::new(), strings: Vec::new(), map: HashMap::new(), - data: Arc::new(data), } } - pub fn func_wrap( + pub fn define(&mut self, module: &str, name: &str, func: F) -> anyhow::Result<()> + where + F: Fn(Caller, P) -> anyhow::Result + Send + Sync + 'static, + P: DeserializeOwned, + R: Serialize, + { + let key = self.import_key(Some(module), name); + + self.insert( + key, + Box::new(move |caller, params| { + let params = postcard::from_bytes(params)?; + + let res = func(caller, params)?; + + Ok(CallResult::Value(postcard::to_allocvec(&res).unwrap())) + }), + )?; + + Ok(()) + } + + pub fn define_async( &mut self, module: &str, name: &str, - func: impl IntoFunc, - ) -> Result<&mut Self> { - let func = func.into_func(); - + func: F, + ) -> anyhow::Result<()> + where + F: Fn(Caller, P) -> Pin> + Send + Sync + 'static, + P: DeserializeOwned, + R: Future> + Send + 'static, + RV: Serialize, + { let key = self.import_key(Some(module), name); - self.insert(key, func)?; - Ok(self) + self.insert( + key, + Box::new(move |caller, params| { + let params = postcard::from_bytes(params)?; + + let fut = func(caller, params) + .map(|res| postcard::to_allocvec(&res?).map_err(Into::into)) + .boxed(); + + Ok(CallResult::Future(fut)) + }), + )?; + + Ok(()) } - pub fn handle_request( - &mut self, - module: Option>, - name: impl AsRef, + async fn call( + &self, + module: Option<&str>, + name: &str, params: &[u8], - app_handle: AppHandle, - tx: Sender>, - ) -> anyhow::Result<()> { - let key = self.import_key(module, name.as_ref()); + ) -> anyhow::Result> { + let key = self.import_key_read_only(module, name)?; let handler = self .map @@ -89,16 +123,16 @@ impl Router { .ok_or(anyhow::anyhow!("method not found"))?; let caller = Caller { - data: &*self.data, - app_handle, + data: self.data.clone(), }; - handler(caller, params, tx)?; - - Ok(()) + match handler(caller, params)? { + CallResult::Value(val) => Ok(val), + CallResult::Future(fut) => Ok(fut.await?), + } } - fn insert(&mut self, key: ImportKey, item: Definition) -> Result<()> { + fn insert(&mut self, key: ImportKey, item: Definition) -> anyhow::Result<()> { match self.map.entry(key) { Entry::Occupied(_) => { let module = &self.strings[key.module]; @@ -106,7 +140,7 @@ impl Router { Some(name) => format!("{module}::{name}"), None => module.to_string(), }; - bail!("import of `{}` defined twice", desc) + anyhow::bail!("import of `{}` defined twice", desc) } Entry::Vacant(v) => { v.insert(item); @@ -122,6 +156,24 @@ impl Router { } } + fn import_key_read_only(&self, module: Option<&str>, name: &str) -> anyhow::Result { + let module = if let Some(module) = module { + *self + .string2idx + .get(module) + .ok_or(anyhow::anyhow!("unknown module"))? + } else { + usize::MAX + }; + + let name = *self + .string2idx + .get(name) + .ok_or(anyhow::anyhow!("unknown function"))?; + + Ok(ImportKey { module, name }) + } + fn intern_str(&mut self, string: &str) -> usize { if let Some(idx) = self.string2idx.get(string) { return *idx; @@ -134,126 +186,21 @@ impl Router { } } -pub trait IntoFunc: Send + Sync { - #[doc(hidden)] - fn into_func(self) -> Definition; -} - -macro_rules! impl_into_func { - ($num:tt $($params:ident)*) => { - // Implement for functions without a leading `&Caller` parameter, - // delegating to the implementation below which does have the leading - // `Caller` parameter. - #[allow(non_snake_case)] - impl IntoFunc for F - where - F: Fn($($params),*) -> anyhow::Result + Send + Sync + 'static, - $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize, - { - fn into_func(self) -> Definition { - let f = move |_: Caller, $($params:$params),*| { - self($($params),*) - }; - - f.into_func() - } - } - - #[allow(non_snake_case)] - impl IntoFunc, $($params,)*), R, Rt> for F - where - F: Fn(Caller, $($params),*) -> anyhow::Result + Send + Sync + 'static, - $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize, - { - fn into_func(self) -> Definition { - Box::new(move |caller, params, tx| { - log::debug!("Deserializing parameters..."); - let ($($params,)*) = postcard::from_bytes(params)?; - - log::debug!("Calling handler..."); - let out = self(caller, $($params),*)?; - - log::debug!("Serializing response..."); - let out = postcard::to_allocvec(&out)?; - - tx.send(out).unwrap(); - - Ok(()) - }) - } - } - } -} - -macro_rules! for_each_function_signature { - ($mac:ident) => { - $mac!(0); - $mac!(1 A1); - $mac!(2 A1 A2); - $mac!(3 A1 A2 A3); - $mac!(4 A1 A2 A3 A4); - $mac!(5 A1 A2 A3 A4 A5); - $mac!(6 A1 A2 A3 A4 A5 A6); - $mac!(7 A1 A2 A3 A4 A5 A6 A7); - $mac!(8 A1 A2 A3 A4 A5 A6 A7 A8); - $mac!(9 A1 A2 A3 A4 A5 A6 A7 A8 A9); - $mac!(10 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10); - $mac!(11 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11); - $mac!(12 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12); - $mac!(13 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13); - $mac!(14 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14); - $mac!(15 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15); - $mac!(16 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16); - }; -} - -for_each_function_signature!(impl_into_func); - -pub trait BuilderExt { +pub trait BuilderExt { #[must_use] - fn ipc_router(self, router: Router) -> Self; + fn ipc_router(self, router: Router) -> Self; } -impl BuilderExt for tauri::Builder { - fn ipc_router(self, mut router: Router) -> Self { - let (tx, mut rx) = mpsc::channel::<(AppHandle, Request>, _)>(250); +impl BuilderExt for tauri::Builder { + fn ipc_router(self, router: Router) -> Self { + let router = Arc::new(router); - let this = - self.register_asynchronous_uri_scheme_protocol("ipc", move |app, req, responder| { - tx.try_send((app.clone(), req, responder)).unwrap(); - }); + self.register_asynchronous_uri_scheme_protocol("ipc", move |_app, req, responder| { + let router = router.clone(); - tauri::async_runtime::handle().spawn(async move { - while let Some((app, req, responder)) = rx.recv().await { - let path = req.uri().path().strip_prefix('/').unwrap(); - - let (module, method) = path - .split_once('/') - .map_or((None, path), |(module, method)| (Some(module), method)); - - log::debug!("ipc request for {:?}::{}", module, method); - - let (tx, rx) = oneshot::channel(); - router - .handle_request(module, method, req.body(), app, tx) - .unwrap(); - let res = rx.await; - - log::debug!("call result {:?}", res); - - let mut response = match res { - Ok(val) => { - let mut resp = Response::builder().status(StatusCode::OK); - resp.headers_mut().unwrap().insert( - CONTENT_TYPE, - tauri::http::header::HeaderValue::from_static( - "application/octet-stream", - ), - ); - resp.body(val).unwrap() - } + tauri::async_runtime::spawn(async move { + let mut response = match uri_scheme_inner(&router, req).await { + Ok(res) => res, Err(err) => Response::builder() .status(StatusCode::BAD_REQUEST) .body(err.to_string().into_bytes()) @@ -266,32 +213,33 @@ impl BuilderExt for tauri::Builder { ); responder.respond(response); - } - }); - - this + }); + }) } } -// async fn uri_scheme_handler_inner( -// app: &AppHandle, -// req: &tauri::http::Request>, -// ) -> anyhow::Result> { -// let path = req.uri().path().strip_prefix('/').unwrap(); +#[inline(always)] +async fn uri_scheme_inner( + router: &Router, + request: Request>, +) -> anyhow::Result>> { + let path = request.uri().path().strip_prefix('/').unwrap(); -// let (module, method) = path -// .split_once('/') -// .map_or((None, path), |(module, method)| (Some(module), method)); + let (module, method) = path + .split_once('/') + .map_or((None, path), |(module, method)| (Some(module), method)); -// log::debug!("ipc request for {:?}::{}", module, method); + log::debug!("ipc request for {:?}::{}", module, method); -// let (res_tx, res_rx) = oneshot::channel(); + let response = router.call(module, method, request.body()).await?; -// let router = app.state::>>(); -// let mut router = router.lock().unwrap(); + log::debug!("call result {:?}", response); -// // this is terrible we should not clone here -// router.handle_request(module, method, req.body(), res_tx)?; + let mut resp = Response::builder().status(StatusCode::OK); + resp.headers_mut().unwrap().insert( + CONTENT_TYPE, + tauri::http::header::HeaderValue::from_static("application/octet-stream"), + ); -// Ok(res_rx.await?) -// } + Ok(resp.body(response)?) +} diff --git a/examples/greet/src-tauri/Cargo.toml b/examples/greet/src-tauri/Cargo.toml index c9951201..cbcc8b21 100644 --- a/examples/greet/src-tauri/Cargo.toml +++ b/examples/greet/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { version = "1.1", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { git = "https://github.com/tauri-apps/tauri" } +tauri = { git = "https://github.com/tauri-apps/tauri", features = [] } tauri-bindgen-host = { path = "../../../crates/host" } tracing-subscriber = "0.3.16" tracing = "0.1.37" diff --git a/examples/greet/src-tauri/src/main.rs b/examples/greet/src-tauri/src/main.rs index f84933dc..2e010041 100644 --- a/examples/greet/src-tauri/src/main.rs +++ b/examples/greet/src-tauri/src/main.rs @@ -8,15 +8,16 @@ use tracing_subscriber; tauri_bindgen_host::generate!({ path: "../greet.wit", - async: false, + async: true, tracing: true }); #[derive(Clone, Copy)] struct GreetCtx; +#[::tauri_bindgen_host::async_trait] impl greet::Greet for GreetCtx { - fn greet(&self, name: String) -> String { + async fn greet(&self, name: String) -> String { format!( "Hello, {}! You've been greeted from code-generated Rust!", name diff --git a/update-fixtures.sh b/update-fixtures.sh index 14928ed2..80f7af55 100755 --- a/update-fixtures.sh +++ b/update-fixtures.sh @@ -1,5 +1,6 @@ cargo build --features unstable -for i in wit/*.wit; do target/debug/tauri-bindgen host --tracing --out-dir crates/gen-host/tests --fmt $i; done +for i in wit/*.wit; do target/debug/tauri-bindgen host --tracing --out-dir crates/gen-host/tests/sync --fmt $i; done +for i in wit/*.wit; do target/debug/tauri-bindgen host --tracing --async --out-dir crates/gen-host/tests/async --fmt $i; done for i in wit/*.wit; do target/debug/tauri-bindgen markdown --out-dir crates/gen-markdown/tests $i; done @@ -7,4 +8,3 @@ for i in wit/*.wit; do target/debug/tauri-bindgen guest rust --out-dir crates/ge for i in wit/*.wit; do target/debug/tauri-bindgen guest javascript --out-dir crates/gen-guest-js/tests $i; done for i in wit/*.wit; do target/debug/tauri-bindgen guest typescript --out-dir crates/gen-guest-ts/tests $i; done # for i in wit/*.wit; do target/debug/tauri-bindgen guest rescript --fmt --out-dir crates/gen-guest-rescript/tests $i; done - From ed04c32c8d2c68f80e3892cbd461a2d982213db3 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Tue, 12 Sep 2023 17:51:02 -0500 Subject: [PATCH 3/7] clippy --- crates/ipc-router-wip/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ipc-router-wip/src/lib.rs b/crates/ipc-router-wip/src/lib.rs index b1227cc0..f0486d39 100644 --- a/crates/ipc-router-wip/src/lib.rs +++ b/crates/ipc-router-wip/src/lib.rs @@ -218,7 +218,7 @@ impl BuilderExt for tauri::Builder { } } -#[inline(always)] +#[inline] async fn uri_scheme_inner( router: &Router, request: Request>, From cdfd63648604345f3dae73edd5c5ac201751c74c Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Thu, 14 Sep 2023 03:12:49 -0600 Subject: [PATCH 4/7] fi CI --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a16ecf25..8acb561d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - name: install native dependecies run: | sudo apt-get update - sudo apt-get install -y webkit2gtk-4.0 libgtk-3-dev + sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} @@ -54,7 +54,7 @@ jobs: - name: install native dependecies run: | sudo apt-get update - sudo apt-get install -y webkit2gtk-4.0 libgtk-3-dev + sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev - uses: dtolnay/rust-toolchain@1.70.0 - uses: Swatinem/rust-cache@v2 - run: cargo check --workspace --tests @@ -69,7 +69,7 @@ jobs: - name: install native dependecies run: | sudo apt-get update - sudo apt-get install -y webkit2gtk-4.0 libgtk-3-dev + sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev - uses: dtolnay/rust-toolchain@stable with: components: clippy From 3811b479e5cae67b95494d546430ab915899fe5f Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Thu, 14 Sep 2023 03:15:14 -0600 Subject: [PATCH 5/7] cleanup --- crates/gen-host/src/lib.rs | 1 - crates/gen-host/tests/async/chars.rs | 5 +- crates/gen-host/tests/async/conventions.rs | 5 +- crates/gen-host/tests/async/empty.rs | 5 +- crates/gen-host/tests/async/flegs.rs | 5 +- crates/gen-host/tests/async/floats.rs | 5 +- crates/gen-host/tests/async/integers.rs | 5 +- crates/gen-host/tests/async/lists.rs | 5 +- crates/gen-host/tests/async/many-arguments.rs | 5 +- crates/gen-host/tests/async/multi-return.rs | 5 +- crates/gen-host/tests/async/records.rs | 5 +- crates/gen-host/tests/async/resources.rs | 5 +- .../gen-host/tests/async/simple-functions.rs | 5 +- crates/gen-host/tests/async/simple-lists.rs | 5 +- .../gen-host/tests/async/small-anonymous.rs | 5 +- crates/gen-host/tests/async/strings.rs | 5 +- crates/gen-host/tests/async/unions.rs | 5 +- crates/gen-host/tests/async/variants.rs | 5 +- crates/gen-host/tests/strings.rs | 65 ------------------- crates/gen-host/tests/sync/chars.rs | 5 +- crates/gen-host/tests/sync/conventions.rs | 5 +- crates/gen-host/tests/sync/empty.rs | 5 +- crates/gen-host/tests/sync/flegs.rs | 5 +- crates/gen-host/tests/sync/floats.rs | 5 +- crates/gen-host/tests/sync/integers.rs | 5 +- crates/gen-host/tests/sync/lists.rs | 5 +- crates/gen-host/tests/sync/many-arguments.rs | 5 +- crates/gen-host/tests/sync/multi-return.rs | 5 +- crates/gen-host/tests/sync/records.rs | 5 +- crates/gen-host/tests/sync/resources.rs | 5 +- .../gen-host/tests/sync/simple-functions.rs | 5 +- crates/gen-host/tests/sync/simple-lists.rs | 5 +- crates/gen-host/tests/sync/small-anonymous.rs | 5 +- crates/gen-host/tests/sync/strings.rs | 5 +- crates/gen-host/tests/sync/unions.rs | 5 +- crates/gen-host/tests/sync/variants.rs | 5 +- 36 files changed, 68 insertions(+), 168 deletions(-) delete mode 100644 crates/gen-host/tests/strings.rs diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index 310dac03..af073bad 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -398,7 +398,6 @@ impl Host { where T: Send + Sync + 'static, U: #trait_ident + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); diff --git a/crates/gen-host/tests/async/chars.rs b/crates/gen-host/tests/async/chars.rs index efe39e74..1a8a576c 100644 --- a/crates/gen-host/tests/async/chars.rs +++ b/crates/gen-host/tests/async/chars.rs @@ -10,14 +10,13 @@ pub mod chars { ///A function that returns a character async fn return_char(&self) -> char; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Chars + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/conventions.rs b/crates/gen-host/tests/async/conventions.rs index fd2fc471..4e1dac96 100644 --- a/crates/gen-host/tests/async/conventions.rs +++ b/crates/gen-host/tests/async/conventions.rs @@ -24,14 +24,13 @@ pub mod conventions { async fn explicit_snake(&self); async fn bool(&self); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Conventions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/empty.rs b/crates/gen-host/tests/async/empty.rs index 304c03ac..eca4c289 100644 --- a/crates/gen-host/tests/async/empty.rs +++ b/crates/gen-host/tests/async/empty.rs @@ -5,14 +5,13 @@ pub mod empty { use ::tauri_bindgen_host::bitflags; #[::tauri_bindgen_host::async_trait] pub trait Empty: Sized {} - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Empty + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); Ok(()) diff --git a/crates/gen-host/tests/async/flegs.rs b/crates/gen-host/tests/async/flegs.rs index fb6d24a3..fa504cf9 100644 --- a/crates/gen-host/tests/async/flegs.rs +++ b/crates/gen-host/tests/async/flegs.rs @@ -68,14 +68,13 @@ pub mod flegs { async fn roundtrip_flag32(&self, x: Flag32) -> Flag32; async fn roundtrip_flag64(&self, x: Flag64) -> Flag64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Flegs + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/floats.rs b/crates/gen-host/tests/async/floats.rs index 7417146d..2fa4d703 100644 --- a/crates/gen-host/tests/async/floats.rs +++ b/crates/gen-host/tests/async/floats.rs @@ -10,14 +10,13 @@ pub mod floats { async fn float32_result(&self) -> f32; async fn float64_result(&self) -> f64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Floats + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/integers.rs b/crates/gen-host/tests/async/integers.rs index 91cf91ce..5d4ea36e 100644 --- a/crates/gen-host/tests/async/integers.rs +++ b/crates/gen-host/tests/async/integers.rs @@ -40,14 +40,13 @@ pub mod integers { async fn r10(&self) -> i128; async fn pair_ret(&self) -> (i64, u8); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Integers + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/lists.rs b/crates/gen-host/tests/async/lists.rs index f6ed020b..0f08c146 100644 --- a/crates/gen-host/tests/async/lists.rs +++ b/crates/gen-host/tests/async/lists.rs @@ -78,14 +78,13 @@ pub mod lists { async fn variant_list(&self, x: Vec) -> Vec; async fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Lists + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/many-arguments.rs b/crates/gen-host/tests/async/many-arguments.rs index 7ea4fcc5..9ebfd1ff 100644 --- a/crates/gen-host/tests/async/many-arguments.rs +++ b/crates/gen-host/tests/async/many-arguments.rs @@ -50,14 +50,13 @@ pub mod many_arguments { ); async fn big_argument(&self, x: BigStruct); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: ManyArguments + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/multi-return.rs b/crates/gen-host/tests/async/multi-return.rs index 729cf8ff..0d2f0fe9 100644 --- a/crates/gen-host/tests/async/multi-return.rs +++ b/crates/gen-host/tests/async/multi-return.rs @@ -11,14 +11,13 @@ pub mod multi_return { async fn mrd(&self) -> u32; async fn mre(&self) -> (u32, f32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: MultiReturn + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/records.rs b/crates/gen-host/tests/async/records.rs index d9c306eb..90281e62 100644 --- a/crates/gen-host/tests/async/records.rs +++ b/crates/gen-host/tests/async/records.rs @@ -56,14 +56,13 @@ All of the fields are bool*/ async fn aggregate_result(&self) -> Aggregates; async fn typedef_inout(&self, e: TupleTypedef2) -> i32; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Records + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/resources.rs b/crates/gen-host/tests/async/resources.rs index 296d1f94..a11f3225 100644 --- a/crates/gen-host/tests/async/resources.rs +++ b/crates/gen-host/tests/async/resources.rs @@ -28,14 +28,13 @@ pub mod resources { async fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; async fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Resources + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/simple-functions.rs b/crates/gen-host/tests/async/simple-functions.rs index 7c65d595..fe5d4665 100644 --- a/crates/gen-host/tests/async/simple-functions.rs +++ b/crates/gen-host/tests/async/simple-functions.rs @@ -12,14 +12,13 @@ pub mod simple_functions { async fn f5(&self) -> (u32, u32); async fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SimpleFunctions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/simple-lists.rs b/crates/gen-host/tests/async/simple-lists.rs index 853d33e5..90e680ad 100644 --- a/crates/gen-host/tests/async/simple-lists.rs +++ b/crates/gen-host/tests/async/simple-lists.rs @@ -10,14 +10,13 @@ pub mod simple_lists { async fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); async fn simple_list4(&self, l: Vec>) -> Vec>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SimpleLists + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/small-anonymous.rs b/crates/gen-host/tests/async/small-anonymous.rs index 2b04c099..0772e27b 100644 --- a/crates/gen-host/tests/async/small-anonymous.rs +++ b/crates/gen-host/tests/async/small-anonymous.rs @@ -13,14 +13,13 @@ pub mod small_anonymous { pub trait SmallAnonymous: Sized { async fn option_test(&self) -> Result, Error>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SmallAnonymous + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/strings.rs b/crates/gen-host/tests/async/strings.rs index 994c34fd..c929e1ca 100644 --- a/crates/gen-host/tests/async/strings.rs +++ b/crates/gen-host/tests/async/strings.rs @@ -9,14 +9,13 @@ pub mod strings { async fn b(&self) -> String; async fn c(&self, a: String, b: String) -> String; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Strings + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/unions.rs b/crates/gen-host/tests/async/unions.rs index d67fe476..9e18c60a 100644 --- a/crates/gen-host/tests/async/unions.rs +++ b/crates/gen-host/tests/async/unions.rs @@ -66,14 +66,13 @@ and is treated that way in some languages*/ ) -> DistinguishableNum; async fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Unions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/async/variants.rs b/crates/gen-host/tests/async/variants.rs index 4737eddb..1c153db1 100644 --- a/crates/gen-host/tests/async/variants.rs +++ b/crates/gen-host/tests/async/variants.rs @@ -146,14 +146,13 @@ pub mod variants { async fn return_named_option(&self) -> Option; async fn return_named_result(&self) -> Result; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Variants + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/strings.rs b/crates/gen-host/tests/strings.rs deleted file mode 100644 index c929e1ca..00000000 --- a/crates/gen-host/tests/strings.rs +++ /dev/null @@ -1,65 +0,0 @@ -#[allow(unused_imports, unused_variables, dead_code)] -#[rustfmt::skip] -pub mod strings { - use ::tauri_bindgen_host::serde; - use ::tauri_bindgen_host::bitflags; - #[::tauri_bindgen_host::async_trait] - pub trait Strings: Sized { - async fn a(&self, x: String); - async fn b(&self) -> String; - async fn c(&self, a: String, b: String) -> String; - } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, - get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, - ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> - where - T: Send + Sync + 'static, - U: Strings + Send + Sync + 'static, - { - let wrapped_get_cx = ::std::sync::Arc::new(get_cx); - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router - .define_async( - "strings", - "a", - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: String| { - let get_cx = get_cx.clone(); - Box::pin(async move { - let ctx = get_cx(ctx.data()); - Ok(ctx.a(p).await) - }) - }, - )?; - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router - .define_async( - "strings", - "b", - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { - let get_cx = get_cx.clone(); - Box::pin(async move { - let ctx = get_cx(ctx.data()); - Ok(ctx.b().await) - }) - }, - )?; - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router - .define_async( - "strings", - "c", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - p: (String, String)| - { - let get_cx = get_cx.clone(); - Box::pin(async move { - let ctx = get_cx(ctx.data()); - Ok(ctx.c(p.0, p.1).await) - }) - }, - )?; - Ok(()) - } -} diff --git a/crates/gen-host/tests/sync/chars.rs b/crates/gen-host/tests/sync/chars.rs index 409faa6b..c1909737 100644 --- a/crates/gen-host/tests/sync/chars.rs +++ b/crates/gen-host/tests/sync/chars.rs @@ -9,14 +9,13 @@ pub mod chars { ///A function that returns a character fn return_char(&self) -> char; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Chars + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/conventions.rs b/crates/gen-host/tests/sync/conventions.rs index f771b498..d21acd7c 100644 --- a/crates/gen-host/tests/sync/conventions.rs +++ b/crates/gen-host/tests/sync/conventions.rs @@ -23,14 +23,13 @@ pub mod conventions { fn explicit_snake(&self); fn bool(&self); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Conventions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/empty.rs b/crates/gen-host/tests/sync/empty.rs index df22c4db..ce40c8c9 100644 --- a/crates/gen-host/tests/sync/empty.rs +++ b/crates/gen-host/tests/sync/empty.rs @@ -4,14 +4,13 @@ pub mod empty { use ::tauri_bindgen_host::serde; use ::tauri_bindgen_host::bitflags; pub trait Empty: Sized {} - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Empty + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); Ok(()) diff --git a/crates/gen-host/tests/sync/flegs.rs b/crates/gen-host/tests/sync/flegs.rs index 2e02e01c..be9dd4f5 100644 --- a/crates/gen-host/tests/sync/flegs.rs +++ b/crates/gen-host/tests/sync/flegs.rs @@ -67,14 +67,13 @@ pub mod flegs { fn roundtrip_flag32(&self, x: Flag32) -> Flag32; fn roundtrip_flag64(&self, x: Flag64) -> Flag64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Flegs + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/floats.rs b/crates/gen-host/tests/sync/floats.rs index aa50984e..d654d4b0 100644 --- a/crates/gen-host/tests/sync/floats.rs +++ b/crates/gen-host/tests/sync/floats.rs @@ -9,14 +9,13 @@ pub mod floats { fn float32_result(&self) -> f32; fn float64_result(&self) -> f64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Floats + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/integers.rs b/crates/gen-host/tests/sync/integers.rs index 499babc2..55149262 100644 --- a/crates/gen-host/tests/sync/integers.rs +++ b/crates/gen-host/tests/sync/integers.rs @@ -39,14 +39,13 @@ pub mod integers { fn r10(&self) -> i128; fn pair_ret(&self) -> (i64, u8); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Integers + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/lists.rs b/crates/gen-host/tests/sync/lists.rs index 1b87547f..50b23edd 100644 --- a/crates/gen-host/tests/sync/lists.rs +++ b/crates/gen-host/tests/sync/lists.rs @@ -77,14 +77,13 @@ pub mod lists { fn variant_list(&self, x: Vec) -> Vec; fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Lists + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/many-arguments.rs b/crates/gen-host/tests/sync/many-arguments.rs index 802cfec5..f5d45765 100644 --- a/crates/gen-host/tests/sync/many-arguments.rs +++ b/crates/gen-host/tests/sync/many-arguments.rs @@ -49,14 +49,13 @@ pub mod many_arguments { ); fn big_argument(&self, x: BigStruct); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: ManyArguments + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/multi-return.rs b/crates/gen-host/tests/sync/multi-return.rs index b3b82870..4f9916d4 100644 --- a/crates/gen-host/tests/sync/multi-return.rs +++ b/crates/gen-host/tests/sync/multi-return.rs @@ -10,14 +10,13 @@ pub mod multi_return { fn mrd(&self) -> u32; fn mre(&self) -> (u32, f32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: MultiReturn + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/records.rs b/crates/gen-host/tests/sync/records.rs index 02df4bd3..716cea3e 100644 --- a/crates/gen-host/tests/sync/records.rs +++ b/crates/gen-host/tests/sync/records.rs @@ -55,14 +55,13 @@ All of the fields are bool*/ fn aggregate_result(&self) -> Aggregates; fn typedef_inout(&self, e: TupleTypedef2) -> i32; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Records + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/resources.rs b/crates/gen-host/tests/sync/resources.rs index dd8e461d..46bbe8f8 100644 --- a/crates/gen-host/tests/sync/resources.rs +++ b/crates/gen-host/tests/sync/resources.rs @@ -25,14 +25,13 @@ pub mod resources { fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Resources + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/simple-functions.rs b/crates/gen-host/tests/sync/simple-functions.rs index 4fd9cae5..7f735cd9 100644 --- a/crates/gen-host/tests/sync/simple-functions.rs +++ b/crates/gen-host/tests/sync/simple-functions.rs @@ -11,14 +11,13 @@ pub mod simple_functions { fn f5(&self) -> (u32, u32); fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SimpleFunctions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/simple-lists.rs b/crates/gen-host/tests/sync/simple-lists.rs index 3fa552ed..eda7e5a9 100644 --- a/crates/gen-host/tests/sync/simple-lists.rs +++ b/crates/gen-host/tests/sync/simple-lists.rs @@ -9,14 +9,13 @@ pub mod simple_lists { fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); fn simple_list4(&self, l: Vec>) -> Vec>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SimpleLists + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/small-anonymous.rs b/crates/gen-host/tests/sync/small-anonymous.rs index 6cce9ef1..d928b772 100644 --- a/crates/gen-host/tests/sync/small-anonymous.rs +++ b/crates/gen-host/tests/sync/small-anonymous.rs @@ -12,14 +12,13 @@ pub mod small_anonymous { pub trait SmallAnonymous: Sized { fn option_test(&self) -> Result, Error>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: SmallAnonymous + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/strings.rs b/crates/gen-host/tests/sync/strings.rs index 608a33ca..68d0b7b9 100644 --- a/crates/gen-host/tests/sync/strings.rs +++ b/crates/gen-host/tests/sync/strings.rs @@ -8,14 +8,13 @@ pub mod strings { fn b(&self) -> String; fn c(&self, a: String, b: String) -> String; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Strings + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/unions.rs b/crates/gen-host/tests/sync/unions.rs index f60869be..500305c4 100644 --- a/crates/gen-host/tests/sync/unions.rs +++ b/crates/gen-host/tests/sync/unions.rs @@ -65,14 +65,13 @@ and is treated that way in some languages*/ ) -> DistinguishableNum; fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Unions + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); diff --git a/crates/gen-host/tests/sync/variants.rs b/crates/gen-host/tests/sync/variants.rs index 50572a87..9c50d88e 100644 --- a/crates/gen-host/tests/sync/variants.rs +++ b/crates/gen-host/tests/sync/variants.rs @@ -145,14 +145,13 @@ pub mod variants { fn return_named_option(&self) -> Option; fn return_named_result(&self) -> Result; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where T: Send + Sync + 'static, U: Variants + Send + Sync + 'static, - R: ::tauri_bindgen_host::tauri::Runtime, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); From e67076b8618c98d12d3c029b0d284f6913be49ae Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Thu, 14 Sep 2023 06:19:32 -0600 Subject: [PATCH 6/7] apply suggestions --- Cargo.toml | 2 +- crates/gen-host/src/lib.rs | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2c91822..240a470e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ serde = "1.0.188" quote = "1.0.33" proc-macro2 = "1.0.67" syn = "2.0.33" -tauri = { git = "https://github.com/tauri-apps/tauri" } +tauri = "2.0.0-alpha.14" [dependencies] clap.workspace = true diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index af073bad..afd80e25 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -340,26 +340,6 @@ impl Host { } }; - // let result = match func.result.as_ref() { - // Some(FunctionResult::Anon(ty)) => { - // let ty = self.print_ty(ty, &BorrowMode::Owned); - - // quote! { #ty } - // } - // Some(FunctionResult::Named(types)) if types.len() == 1 => { - // let (_, ty) = &types[0]; - // let ty = self.print_ty(ty, &BorrowMode::Owned); - - // quote! { #ty } - // } - // Some(FunctionResult::Named(types)) => { - // let types = types.iter().map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); - - // quote! { (#(#types),*) } - // } - // _ => quote! { () }, - // }; - if self.opts.async_ { quote! { let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); From ba766f392f6174171bae7e3e4c2b1f3f78568be7 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Thu, 14 Sep 2023 07:16:01 -0600 Subject: [PATCH 7/7] fix: async resource --- crates/gen-host/src/lib.rs | 232 +++++++++--------- crates/gen-host/tests/async/resources.rs | 122 ++++++++- crates/gen-host/tests/sync/resources.rs | 71 +++--- crates/gen-markdown/tests/chars.md | 4 +- crates/gen-markdown/tests/conventions.md | 24 +- crates/gen-markdown/tests/flegs.md | 14 +- crates/gen-markdown/tests/floats.md | 8 +- crates/gen-markdown/tests/integers.md | 44 ++-- crates/gen-markdown/tests/lists.md | 66 ++--- crates/gen-markdown/tests/many-arguments.md | 4 +- crates/gen-markdown/tests/multi-return.md | 10 +- crates/gen-markdown/tests/records.md | 22 +- crates/gen-markdown/tests/resources.md | 4 +- crates/gen-markdown/tests/simple-functions.md | 12 +- crates/gen-markdown/tests/simple-lists.md | 8 +- crates/gen-markdown/tests/small-anonymous.md | 2 +- crates/gen-markdown/tests/strings.md | 6 +- crates/gen-markdown/tests/unions.md | 20 +- crates/gen-markdown/tests/variants.md | 48 ++-- src/main.rs | 2 +- 20 files changed, 422 insertions(+), 301 deletions(-) diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index 83962cbe..dda46a67 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -310,135 +310,145 @@ impl Host { } } - fn print_add_to_router<'a>( - &self, - mod_ident: &str, - functions: impl Iterator, - methods: impl Iterator, - ) -> TokenStream { - let trait_ident = format_ident!("{}", mod_ident.to_upper_camel_case()); - - let mod_name = mod_ident.to_snake_case(); - - let functions = functions.map(|func| { - let func_name = func.ident.to_snake_case(); - let func_ident = format_ident!("{}", func_name); - - let param_decl = match func.params.len() { - 0 => quote! { () }, - 1 => { - let ty = &func.params.first().unwrap().1; - let ty = self.print_ty(ty, &BorrowMode::Owned); - quote! { #ty } - } - _ => { - let tys = func - .params - .iter() - .map(|(_, ty)| { self.print_ty(ty, &BorrowMode::Owned) }); - quote! { (#(#tys),*) } - } - }; - - let param_acc = match func.params.len() { - 0 => quote! { }, - 1 => quote! { p }, - _ => { - let ids = func - .params - .iter() - .enumerate() - .map(|(i, _)| { - let i = Literal::usize_unsuffixed(i); - quote! { p.#i } - }); - quote! { #(#ids),* } - } - }; + fn print_router_fn_definition(&self, mod_name: &str, func: &Function) -> TokenStream { + let func_name = func.ident.to_snake_case(); + let func_ident = format_ident!("{}", func_name); + + let param_decl = match func.params.len() { + 0 => quote! { () }, + 1 => { + let ty = &func.params.first().unwrap().1; + let ty = self.print_ty(ty, &BorrowMode::Owned); + quote! { #ty } + } + _ => { + let tys = func + .params + .iter() + .map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); + quote! { (#(#tys),*) } + } + }; + + let param_acc = match func.params.len() { + 0 => quote! {}, + 1 => quote! { p }, + _ => { + let ids = func.params.iter().enumerate().map(|(i, _)| { + let i = Literal::usize_unsuffixed(i); + quote! { p.#i } + }); + quote! { #(#ids),* } + } + }; - if self.opts.async_ { - quote! { - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router.define_async( - #mod_name, - #func_name, - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { - let get_cx = get_cx.clone(); - Box::pin(async move { - let ctx = get_cx(ctx.data()); - Ok(ctx.#func_ident(#param_acc).await) - }) - })?; - } - } else { - quote! { - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router.define( - #mod_name, - #func_name, - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { + if self.opts.async_ { + quote! { + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router.define_async( + #mod_name, + #func_name, + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { + let get_cx = get_cx.clone(); + Box::pin(async move { let ctx = get_cx(ctx.data()); - - Ok(ctx.#func_ident(#param_acc)) - }, - )?; - } + Ok(ctx.#func_ident(#param_acc).await) + }) + })?; } - }); - - let methods = methods.map(|(resource_name, method)| { - let func_name = method.ident.to_snake_case(); - let func_ident = format_ident!("{}", func_name); - - let params = self.print_function_params(&method.params, &BorrowMode::Owned); - - let param_idents = method - .params - .iter() - .map(|(ident, _)| format_ident!("{}", ident)); - - let result = match method.result.as_ref() { - Some(FunctionResult::Anon(ty)) => { - let ty = self.print_ty(ty, &BorrowMode::Owned); + } else { + quote! { + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router.define( + #mod_name, + #func_name, + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: #param_decl| { + let ctx = get_cx(ctx.data()); - quote! { #ty } - } - Some(FunctionResult::Named(types)) if types.len() == 1 => { - let (_, ty) = &types[0]; - let ty = self.print_ty(ty, &BorrowMode::Owned); + Ok(ctx.#func_ident(#param_acc)) + }, + )?; + } + } + } - quote! { #ty } - } - Some(FunctionResult::Named(types)) => { - let types = types - .iter() - .map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); + fn print_router_method_definition( + &self, + mod_name: &str, + resource_name: &str, + method: &Function, + ) -> TokenStream { + let func_name = method.ident.to_snake_case(); + let func_ident = format_ident!("{}", func_name); - quote! { (#(#types),*) } - } - _ => quote! { () }, - }; + let param_decl = method + .params + .iter() + .map(|(_, ty)| self.print_ty(ty, &BorrowMode::Owned)); + + let param_acc = match method.params.len() { + 0 => quote! {}, + 1 => quote! { p.1 }, + _ => { + let ids = method.params.iter().enumerate().map(|(i, _)| { + let i = Literal::usize_unsuffixed(i + 1); + quote! { p.#i } + }); + quote! { #(#ids),* } + } + }; - let mod_name = format!("{mod_name}::resource::{resource_name}"); - let get_r_ident = format_ident!("get_{}", resource_name.to_snake_case()); + let mod_name = format!("{mod_name}::resource::{resource_name}"); + let get_r_ident = format_ident!("get_{}", resource_name.to_snake_case()); + if self.opts.async_ { + quote! { + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router.define_async( + #mod_name, + #func_name, + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: (::tauri_bindgen_host::ResourceId, #(#param_decl),*)| { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.#get_r_ident(p.0)?; + Ok(r.#func_ident(#param_acc).await) + }) + })?; + } + } else { quote! { let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router.func_wrap( + router.define( #mod_name, #func_name, move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - #params - | -> ::tauri_bindgen_host::anyhow::Result<#result> { + p: (::tauri_bindgen_host::ResourceId, #(#param_decl),*) + | { let ctx = get_cx(ctx.data()); - let r = ctx.#get_r_ident(this_rid)?; - - Ok(r.#func_ident(#(#param_idents),*)) + let r = ctx.#get_r_ident(p.0)?; + Ok(r.#func_ident(#param_acc)) }, )?; } + } + } + + fn print_add_to_router<'a>( + &self, + mod_ident: &str, + functions: impl Iterator, + methods: impl Iterator, + ) -> TokenStream { + let trait_ident = format_ident!("{}", mod_ident.to_upper_camel_case()); + + let mod_name = mod_ident.to_snake_case(); + + let functions = functions.map(|func| self.print_router_fn_definition(&mod_name, func)); + + let methods = methods.map(|(resource_name, method)| { + self.print_router_method_definition(&mod_name, resource_name, method) }); quote! { diff --git a/crates/gen-host/tests/async/resources.rs b/crates/gen-host/tests/async/resources.rs index a11f3225..f5751e5a 100644 --- a/crates/gen-host/tests/async/resources.rs +++ b/crates/gen-host/tests/async/resources.rs @@ -21,10 +21,16 @@ pub mod resources { } #[::tauri_bindgen_host::async_trait] pub trait Resources: Sized { - type A: A; - fn get_a_mut(&mut self, id: ::tauri_bindgen_host::ResourceId) -> &mut Self::A; - type B: B; - fn get_b_mut(&mut self, id: ::tauri_bindgen_host::ResourceId) -> &mut Self::B; + type A: A + Send + Sync; + fn get_a( + &self, + id: ::tauri_bindgen_host::ResourceId, + ) -> ::tauri_bindgen_host::Result<::std::sync::Arc>; + type B: B + Send + Sync; + fn get_b( + &self, + id: ::tauri_bindgen_host::ResourceId, + ) -> ::tauri_bindgen_host::Result<::std::sync::Arc>; async fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; async fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } @@ -63,6 +69,114 @@ pub mod resources { }) }, )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::a", + "f1", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (::tauri_bindgen_host::ResourceId,)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_a(p.0)?; + Ok(r.f1().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::a", + "f2", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (::tauri_bindgen_host::ResourceId, u32)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_a(p.0)?; + Ok(r.f2(p.1).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::a", + "f3", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (::tauri_bindgen_host::ResourceId, u32, u32)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_a(p.0)?; + Ok(r.f3(p.1, p.2).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::b", + "f1", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (::tauri_bindgen_host::ResourceId,)| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_b(p.0)?; + Ok(r.f1().await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::b", + "f2", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + ::tauri_bindgen_host::ResourceId, + ::tauri_bindgen_host::ResourceId, + )| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_b(p.0)?; + Ok(r.f2(p.1).await) + }) + }, + )?; + let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); + router + .define_async( + "resources::resource::b", + "f3", + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: ( + ::tauri_bindgen_host::ResourceId, + Option>, + )| + { + let get_cx = get_cx.clone(); + Box::pin(async move { + let ctx = get_cx(ctx.data()); + let r = ctx.get_b(p.0)?; + Ok(r.f3(p.1).await) + }) + }, + )?; Ok(()) } } diff --git a/crates/gen-host/tests/sync/resources.rs b/crates/gen-host/tests/sync/resources.rs index af36229e..6022bb10 100644 --- a/crates/gen-host/tests/sync/resources.rs +++ b/crates/gen-host/tests/sync/resources.rs @@ -62,95 +62,92 @@ pub mod resources { )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::a", "f1", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + p: (::tauri_bindgen_host::ResourceId,)| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_a(this_rid)?; + let r = ctx.get_a(p.0)?; Ok(r.f1()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::a", "f2", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - a: u32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + p: (::tauri_bindgen_host::ResourceId, u32)| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_a(this_rid)?; - Ok(r.f2(a)) + let r = ctx.get_a(p.0)?; + Ok(r.f2(p.1)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::a", "f3", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - a: u32, - b: u32, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + p: (::tauri_bindgen_host::ResourceId, u32, u32)| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_a(this_rid)?; - Ok(r.f3(a, b)) + let r = ctx.get_a(p.0)?; + Ok(r.f3(p.1, p.2)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::b", "f1", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - | -> ::tauri_bindgen_host::anyhow::Result< - ::tauri_bindgen_host::ResourceId, - > { + p: (::tauri_bindgen_host::ResourceId,)| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_b(this_rid)?; + let r = ctx.get_b(p.0)?; Ok(r.f1()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::b", "f2", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - x: ::tauri_bindgen_host::ResourceId, - | -> ::tauri_bindgen_host::anyhow::Result> { + p: ( + ::tauri_bindgen_host::ResourceId, + ::tauri_bindgen_host::ResourceId, + )| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_b(this_rid)?; - Ok(r.f2(x)) + let r = ctx.get_b(p.0)?; + Ok(r.f2(p.1)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "resources::resource::b", "f3", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - this_rid: ::tauri_bindgen_host::ResourceId, - x: Option>, - | -> ::tauri_bindgen_host::anyhow::Result< - Result<::tauri_bindgen_host::ResourceId, ()>, - > { + p: ( + ::tauri_bindgen_host::ResourceId, + Option>, + )| + { let ctx = get_cx(ctx.data()); - let r = ctx.get_b(this_rid)?; - Ok(r.f3(x)) + let r = ctx.get_b(p.0)?; + Ok(r.f3(p.1)) }, )?; Ok(()) diff --git a/crates/gen-markdown/tests/chars.md b/crates/gen-markdown/tests/chars.md index c335ad12..5c69398b 100644 --- a/crates/gen-markdown/tests/chars.md +++ b/crates/gen-markdown/tests/chars.md @@ -10,11 +10,11 @@ ### Function take_char -`func take_char (x: char)` +` func take_char (x: char)` A function that accepts a character ### Function return_char -`func return_char () -> char` +` func return_char () -> char` A function that returns a character \ No newline at end of file diff --git a/crates/gen-markdown/tests/conventions.md b/crates/gen-markdown/tests/conventions.md index a3597f57..c5ac04d9 100644 --- a/crates/gen-markdown/tests/conventions.md +++ b/crates/gen-markdown/tests/conventions.md @@ -20,60 +20,60 @@ ### Function kebab_case -`func kebab_case ()` +` func kebab_case ()` ### Function foo -`func foo (x: [ludicrous_speed](#ludicrous_speed))` +` func foo (x: [ludicrous_speed](#ludicrous_speed))` ### Function function_with_underscores -`func function_with_underscores ()` +` func function_with_underscores ()` ### Function function_with_no_weird_characters -`func function_with_no_weird_characters ()` +` func function_with_no_weird_characters ()` ### Function apple -`func apple ()` +` func apple ()` ### Function apple_pear -`func apple_pear ()` +` func apple_pear ()` ### Function apple_pear_grape -`func apple_pear_grape ()` +` func apple_pear_grape ()` ### Function a0 -`func a0 ()` +` func a0 ()` ### Function is_XML -`func is_XML ()` +` func is_XML ()` ### Function explicit -`func explicit ()` +` func explicit ()` ### Function explicit_snake -`func explicit_snake ()` +` func explicit_snake ()` ### Function bool -`func bool ()` +` func bool ()` diff --git a/crates/gen-markdown/tests/flegs.md b/crates/gen-markdown/tests/flegs.md index a23dddd4..faf3970c 100644 --- a/crates/gen-markdown/tests/flegs.md +++ b/crates/gen-markdown/tests/flegs.md @@ -312,35 +312,35 @@ ### Function roundtrip_flag1 -`func roundtrip_flag1 (x: [flag1](#flag1)) -> [flag1](#flag1)` +` func roundtrip_flag1 (x: [flag1](#flag1)) -> [flag1](#flag1)` ### Function roundtrip_flag2 -`func roundtrip_flag2 (x: [flag2](#flag2)) -> [flag2](#flag2)` +` func roundtrip_flag2 (x: [flag2](#flag2)) -> [flag2](#flag2)` ### Function roundtrip_flag4 -`func roundtrip_flag4 (x: [flag4](#flag4)) -> [flag4](#flag4)` +` func roundtrip_flag4 (x: [flag4](#flag4)) -> [flag4](#flag4)` ### Function roundtrip_flag8 -`func roundtrip_flag8 (x: [flag8](#flag8)) -> [flag8](#flag8)` +` func roundtrip_flag8 (x: [flag8](#flag8)) -> [flag8](#flag8)` ### Function roundtrip_flag16 -`func roundtrip_flag16 (x: [flag16](#flag16)) -> [flag16](#flag16)` +` func roundtrip_flag16 (x: [flag16](#flag16)) -> [flag16](#flag16)` ### Function roundtrip_flag32 -`func roundtrip_flag32 (x: [flag32](#flag32)) -> [flag32](#flag32)` +` func roundtrip_flag32 (x: [flag32](#flag32)) -> [flag32](#flag32)` ### Function roundtrip_flag64 -`func roundtrip_flag64 (x: [flag64](#flag64)) -> [flag64](#flag64)` +` func roundtrip_flag64 (x: [flag64](#flag64)) -> [flag64](#flag64)` diff --git a/crates/gen-markdown/tests/floats.md b/crates/gen-markdown/tests/floats.md index 0faea39b..100c96d1 100644 --- a/crates/gen-markdown/tests/floats.md +++ b/crates/gen-markdown/tests/floats.md @@ -10,20 +10,20 @@ ### Function float32_param -`func float32_param (x: float32)` +` func float32_param (x: float32)` ### Function float64_param -`func float64_param (x: float64)` +` func float64_param (x: float64)` ### Function float32_result -`func float32_result () -> float32` +` func float32_result () -> float32` ### Function float64_result -`func float64_result () -> float64` +` func float64_result () -> float64` diff --git a/crates/gen-markdown/tests/integers.md b/crates/gen-markdown/tests/integers.md index 5e38429f..eea7a62d 100644 --- a/crates/gen-markdown/tests/integers.md +++ b/crates/gen-markdown/tests/integers.md @@ -10,110 +10,110 @@ ### Function a1 -`func a1 (x: u8)` +` func a1 (x: u8)` ### Function a2 -`func a2 (x: s8)` +` func a2 (x: s8)` ### Function a3 -`func a3 (x: u16)` +` func a3 (x: u16)` ### Function a4 -`func a4 (x: s16)` +` func a4 (x: s16)` ### Function a5 -`func a5 (x: u32)` +` func a5 (x: u32)` ### Function a6 -`func a6 (x: s32)` +` func a6 (x: s32)` ### Function a7 -`func a7 (x: u64)` +` func a7 (x: u64)` ### Function a8 -`func a8 (x: s64)` +` func a8 (x: s64)` ### Function a9 -`func a9 (x: u128)` +` func a9 (x: u128)` ### Function a10 -`func a10 (x: s128)` +` func a10 (x: s128)` ### Function a11 -`func a11 (p1: u8, p2: s8, p3: u16, p4: s16, p5: u32, p6: s32, p7: u64, p8: s64, p9: u128, p10: s128)` +` func a11 (p1: u8, p2: s8, p3: u16, p4: s16, p5: u32, p6: s32, p7: u64, p8: s64, p9: u128, p10: s128)` ### Function r1 -`func r1 () -> u8` +` func r1 () -> u8` ### Function r2 -`func r2 () -> s8` +` func r2 () -> s8` ### Function r3 -`func r3 () -> u16` +` func r3 () -> u16` ### Function r4 -`func r4 () -> s16` +` func r4 () -> s16` ### Function r5 -`func r5 () -> u32` +` func r5 () -> u32` ### Function r6 -`func r6 () -> s32` +` func r6 () -> s32` ### Function r7 -`func r7 () -> u64` +` func r7 () -> u64` ### Function r8 -`func r8 () -> s64` +` func r8 () -> s64` ### Function r9 -`func r9 () -> u128` +` func r9 () -> u128` ### Function r10 -`func r10 () -> s128` +` func r10 () -> s128` ### Function pair_ret -`func pair_ret () -> tuple` +` func pair_ret () -> tuple` diff --git a/crates/gen-markdown/tests/lists.md b/crates/gen-markdown/tests/lists.md index 25a85733..0fd333b1 100644 --- a/crates/gen-markdown/tests/lists.md +++ b/crates/gen-markdown/tests/lists.md @@ -82,165 +82,165 @@ ### Function list_u8_param -`func list_u8_param (x: list)` +` func list_u8_param (x: list)` ### Function list_u16_param -`func list_u16_param (x: list)` +` func list_u16_param (x: list)` ### Function list_u32_param -`func list_u32_param (x: list)` +` func list_u32_param (x: list)` ### Function list_u64_param -`func list_u64_param (x: list)` +` func list_u64_param (x: list)` ### Function list_u128_param -`func list_u128_param (x: list)` +` func list_u128_param (x: list)` ### Function list_s8_param -`func list_s8_param (x: list)` +` func list_s8_param (x: list)` ### Function list_s16_param -`func list_s16_param (x: list)` +` func list_s16_param (x: list)` ### Function list_s32_param -`func list_s32_param (x: list)` +` func list_s32_param (x: list)` ### Function list_s64_param -`func list_s64_param (x: list)` +` func list_s64_param (x: list)` ### Function list_s128_param -`func list_s128_param (x: list)` +` func list_s128_param (x: list)` ### Function list_float32_param -`func list_float32_param (x: list)` +` func list_float32_param (x: list)` ### Function list_float64_param -`func list_float64_param (x: list)` +` func list_float64_param (x: list)` ### Function list_u8_ret -`func list_u8_ret () -> list` +` func list_u8_ret () -> list` ### Function list_u16_ret -`func list_u16_ret () -> list` +` func list_u16_ret () -> list` ### Function list_u32_ret -`func list_u32_ret () -> list` +` func list_u32_ret () -> list` ### Function list_u64_ret -`func list_u64_ret () -> list` +` func list_u64_ret () -> list` ### Function list_u128_ret -`func list_u128_ret () -> list` +` func list_u128_ret () -> list` ### Function list_s8_ret -`func list_s8_ret () -> list` +` func list_s8_ret () -> list` ### Function list_s16_ret -`func list_s16_ret () -> list` +` func list_s16_ret () -> list` ### Function list_s32_ret -`func list_s32_ret () -> list` +` func list_s32_ret () -> list` ### Function list_s64_ret -`func list_s64_ret () -> list` +` func list_s64_ret () -> list` ### Function list_s128_ret -`func list_s128_ret () -> list` +` func list_s128_ret () -> list` ### Function list_float32_ret -`func list_float32_ret () -> list` +` func list_float32_ret () -> list` ### Function list_float64_ret -`func list_float64_ret () -> list` +` func list_float64_ret () -> list` ### Function tuple_list -`func tuple_list (x: list>) -> list>` +` func tuple_list (x: list>) -> list>` ### Function string_list_arg -`func string_list_arg (a: list)` +` func string_list_arg (a: list)` ### Function string_list_ret -`func string_list_ret () -> list` +` func string_list_ret () -> list` ### Function tuple_string_list -`func tuple_string_list (x: list>) -> list>` +` func tuple_string_list (x: list>) -> list>` ### Function string_list -`func string_list (x: list) -> list` +` func string_list (x: list) -> list` ### Function record_list -`func record_list (x: list<[some_record](#some_record)>) -> list<[other_record](#other_record)>` +` func record_list (x: list<[some_record](#some_record)>) -> list<[other_record](#other_record)>` ### Function record_list_reverse -`func record_list_reverse (x: list<[other_record](#other_record)>) -> list<[some_record](#some_record)>` +` func record_list_reverse (x: list<[other_record](#other_record)>) -> list<[some_record](#some_record)>` ### Function variant_list -`func variant_list (x: list<[some_variant](#some_variant)>) -> list<[other_variant](#other_variant)>` +` func variant_list (x: list<[some_variant](#some_variant)>) -> list<[other_variant](#other_variant)>` ### Function load_store_everything -`func load_store_everything (a: [load_store_all_sizes](#load_store_all_sizes)) -> [load_store_all_sizes](#load_store_all_sizes)` +` func load_store_everything (a: [load_store_all_sizes](#load_store_all_sizes)) -> [load_store_all_sizes](#load_store_all_sizes)` diff --git a/crates/gen-markdown/tests/many-arguments.md b/crates/gen-markdown/tests/many-arguments.md index 07ba432e..0c417cdf 100644 --- a/crates/gen-markdown/tests/many-arguments.md +++ b/crates/gen-markdown/tests/many-arguments.md @@ -56,10 +56,10 @@ ### Function many_args -`func many_args (a1: u64, a2: u64, a3: u64, a4: u64, a5: u64, a6: u64, a7: u64, a8: u64, a9: u64, a10: u64, a11: u64, a12: u64, a13: u64, a14: u64, a15: u64, a16: u64)` +` func many_args (a1: u64, a2: u64, a3: u64, a4: u64, a5: u64, a6: u64, a7: u64, a8: u64, a9: u64, a10: u64, a11: u64, a12: u64, a13: u64, a14: u64, a15: u64, a16: u64)` ### Function big_argument -`func big_argument (x: [big_struct](#big_struct))` +` func big_argument (x: [big_struct](#big_struct))` diff --git a/crates/gen-markdown/tests/multi-return.md b/crates/gen-markdown/tests/multi-return.md index d790759a..ab5d8a51 100644 --- a/crates/gen-markdown/tests/multi-return.md +++ b/crates/gen-markdown/tests/multi-return.md @@ -10,25 +10,25 @@ ### Function mra -`func mra ()` +` func mra ()` ### Function mrb -`func mrb () -> ()` +` func mrb () -> ()` ### Function mrc -`func mrc () -> u32` +` func mrc () -> u32` ### Function mrd -`func mrd () -> (a: u32)` +` func mrd () -> (a: u32)` ### Function mre -`func mre () -> (a: u32, b: float32)` +` func mre () -> (a: u32, b: float32)` diff --git a/crates/gen-markdown/tests/records.md b/crates/gen-markdown/tests/records.md index 6db8d4b9..326a40a2 100644 --- a/crates/gen-markdown/tests/records.md +++ b/crates/gen-markdown/tests/records.md @@ -81,55 +81,55 @@ All of the fields are bool ### Function tuple_arg -`func tuple_arg (x: tuple)` +` func tuple_arg (x: tuple)` ### Function tuple_result -`func tuple_result () -> tuple` +` func tuple_result () -> tuple` ### Function empty_arg -`func empty_arg (x: [empty](#empty))` +` func empty_arg (x: [empty](#empty))` ### Function empty_result -`func empty_result () -> [empty](#empty)` +` func empty_result () -> [empty](#empty)` ### Function scalar_arg -`func scalar_arg (x: [scalars](#scalars))` +` func scalar_arg (x: [scalars](#scalars))` ### Function scalar_result -`func scalar_result () -> [scalars](#scalars)` +` func scalar_result () -> [scalars](#scalars)` ### Function flags_arg -`func flags_arg (x: [really_flags](#really_flags))` +` func flags_arg (x: [really_flags](#really_flags))` ### Function flags_result -`func flags_result () -> [really_flags](#really_flags)` +` func flags_result () -> [really_flags](#really_flags)` ### Function aggregate_arg -`func aggregate_arg (x: [aggregates](#aggregates))` +` func aggregate_arg (x: [aggregates](#aggregates))` ### Function aggregate_result -`func aggregate_result () -> [aggregates](#aggregates)` +` func aggregate_result () -> [aggregates](#aggregates)` ### Function typedef_inout -`func typedef_inout (e: [tuple_typedef2](#tuple_typedef2)) -> s32` +` func typedef_inout (e: [tuple_typedef2](#tuple_typedef2)) -> s32` diff --git a/crates/gen-markdown/tests/resources.md b/crates/gen-markdown/tests/resources.md index 9e7459f6..c484b24a 100644 --- a/crates/gen-markdown/tests/resources.md +++ b/crates/gen-markdown/tests/resources.md @@ -47,10 +47,10 @@ ### Function constructor_a -`func constructor_a () -> [a](#a)` +` func constructor_a () -> [a](#a)` ### Function constructor_b -`func constructor_b () -> [b](#b)` +` func constructor_b () -> [b](#b)` diff --git a/crates/gen-markdown/tests/simple-functions.md b/crates/gen-markdown/tests/simple-functions.md index 0a25f434..64a0a11a 100644 --- a/crates/gen-markdown/tests/simple-functions.md +++ b/crates/gen-markdown/tests/simple-functions.md @@ -10,30 +10,30 @@ ### Function f1 -`func f1 ()` +` func f1 ()` ### Function f2 -`func f2 (a: u32)` +` func f2 (a: u32)` ### Function f3 -`func f3 (a: u32, b: u32)` +` func f3 (a: u32, b: u32)` ### Function f4 -`func f4 () -> u32` +` func f4 () -> u32` ### Function f5 -`func f5 () -> tuple` +` func f5 () -> tuple` ### Function f6 -`func f6 (a: u32, b: u32, c: u32) -> tuple` +` func f6 (a: u32, b: u32, c: u32) -> tuple` diff --git a/crates/gen-markdown/tests/simple-lists.md b/crates/gen-markdown/tests/simple-lists.md index d5e139bd..90a97245 100644 --- a/crates/gen-markdown/tests/simple-lists.md +++ b/crates/gen-markdown/tests/simple-lists.md @@ -10,20 +10,20 @@ ### Function simple_list1 -`func simple_list1 (l: list)` +` func simple_list1 (l: list)` ### Function simple_list2 -`func simple_list2 () -> list` +` func simple_list2 () -> list` ### Function simple_list3 -`func simple_list3 (a: list, b: list) -> tuple, list>` +` func simple_list3 (a: list, b: list) -> tuple, list>` ### Function simple_list4 -`func simple_list4 (l: list>) -> list>` +` func simple_list4 (l: list>) -> list>` diff --git a/crates/gen-markdown/tests/small-anonymous.md b/crates/gen-markdown/tests/small-anonymous.md index 2afb7f89..d572cf9d 100644 --- a/crates/gen-markdown/tests/small-anonymous.md +++ b/crates/gen-markdown/tests/small-anonymous.md @@ -20,5 +20,5 @@ ### Function option_test -`func option_test () -> result, [error](#error)>` +` func option_test () -> result, [error](#error)>` diff --git a/crates/gen-markdown/tests/strings.md b/crates/gen-markdown/tests/strings.md index 15e492d4..a18900c3 100644 --- a/crates/gen-markdown/tests/strings.md +++ b/crates/gen-markdown/tests/strings.md @@ -10,15 +10,15 @@ ### Function a -`func a (x: string)` +` func a (x: string)` ### Function b -`func b () -> string` +` func b () -> string` ### Function c -`func c (a: string, b: string) -> string` +` func c (a: string, b: string) -> string` diff --git a/crates/gen-markdown/tests/unions.md b/crates/gen-markdown/tests/unions.md index e2ad318f..e4c6e589 100644 --- a/crates/gen-markdown/tests/unions.md +++ b/crates/gen-markdown/tests/unions.md @@ -81,50 +81,50 @@ A Signed Integer ### Function add_one_integer -`func add_one_integer (num: [all_integers](#all_integers)) -> [all_integers](#all_integers)` +` func add_one_integer (num: [all_integers](#all_integers)) -> [all_integers](#all_integers)` ### Function add_one_float -`func add_one_float (num: [all_floats](#all_floats)) -> [all_floats](#all_floats)` +` func add_one_float (num: [all_floats](#all_floats)) -> [all_floats](#all_floats)` ### Function replace_first_char -`func replace_first_char (text: [all_text](#all_text), letter: char) -> [all_text](#all_text)` +` func replace_first_char (text: [all_text](#all_text), letter: char) -> [all_text](#all_text)` ### Function identify_integer -`func identify_integer (num: [all_integers](#all_integers)) -> u8` +` func identify_integer (num: [all_integers](#all_integers)) -> u8` ### Function identify_float -`func identify_float (num: [all_floats](#all_floats)) -> u8` +` func identify_float (num: [all_floats](#all_floats)) -> u8` ### Function identify_text -`func identify_text (text: [all_text](#all_text)) -> u8` +` func identify_text (text: [all_text](#all_text)) -> u8` ### Function add_one_duplicated -`func add_one_duplicated (num: [duplicated_s32](#duplicated_s32)) -> [duplicated_s32](#duplicated_s32)` +` func add_one_duplicated (num: [duplicated_s32](#duplicated_s32)) -> [duplicated_s32](#duplicated_s32)` ### Function identify_duplicated -`func identify_duplicated (num: [duplicated_s32](#duplicated_s32)) -> u8` +` func identify_duplicated (num: [duplicated_s32](#duplicated_s32)) -> u8` ### Function add_one_distinguishable_num -`func add_one_distinguishable_num (num: [distinguishable_num](#distinguishable_num)) -> [distinguishable_num](#distinguishable_num)` +` func add_one_distinguishable_num (num: [distinguishable_num](#distinguishable_num)) -> [distinguishable_num](#distinguishable_num)` ### Function identify_distinguishable_num -`func identify_distinguishable_num (num: [distinguishable_num](#distinguishable_num)) -> u8` +` func identify_distinguishable_num (num: [distinguishable_num](#distinguishable_num)) -> u8` diff --git a/crates/gen-markdown/tests/variants.md b/crates/gen-markdown/tests/variants.md index 0caa87b0..3a650789 100644 --- a/crates/gen-markdown/tests/variants.md +++ b/crates/gen-markdown/tests/variants.md @@ -143,120 +143,120 @@ ### Function e1_arg -`func e1_arg (x: [e1](#e1))` +` func e1_arg (x: [e1](#e1))` ### Function e1_result -`func e1_result () -> [e1](#e1)` +` func e1_result () -> [e1](#e1)` ### Function u1_arg -`func u1_arg (x: [u1](#u1))` +` func u1_arg (x: [u1](#u1))` ### Function u1_result -`func u1_result () -> [u1](#u1)` +` func u1_result () -> [u1](#u1)` ### Function v1_arg -`func v1_arg (x: [v1](#v1))` +` func v1_arg (x: [v1](#v1))` ### Function v1_result -`func v1_result () -> [v1](#v1)` +` func v1_result () -> [v1](#v1)` ### Function bool_arg -`func bool_arg (x: bool)` +` func bool_arg (x: bool)` ### Function bool_result -`func bool_result () -> bool` +` func bool_result () -> bool` ### Function option_arg -`func option_arg (a: option, b: option>, c: option, d: option<[e1](#e1)>, e: option, f: option<[u1](#u1)>, g: option>)` +` func option_arg (a: option, b: option>, c: option, d: option<[e1](#e1)>, e: option, f: option<[u1](#u1)>, g: option>)` ### Function option_result -`func option_result () -> tuple, option>, option, option<[e1](#e1)>, option, option<[u1](#u1)>, option>>` +` func option_result () -> tuple, option>, option, option<[e1](#e1)>, option, option<[u1](#u1)>, option>>` ### Function casts -`func casts (a: [casts1](#casts1), b: [casts2](#casts2), c: [casts3](#casts3), d: [casts4](#casts4), e: [casts5](#casts5), f: [casts6](#casts6)) -> tuple<[casts1](#casts1), [casts2](#casts2), [casts3](#casts3), [casts4](#casts4), [casts5](#casts5), [casts6](#casts6)>` +` func casts (a: [casts1](#casts1), b: [casts2](#casts2), c: [casts3](#casts3), d: [casts4](#casts4), e: [casts5](#casts5), f: [casts6](#casts6)) -> tuple<[casts1](#casts1), [casts2](#casts2), [casts3](#casts3), [casts4](#casts4), [casts5](#casts5), [casts6](#casts6)>` ### Function result_arg -`func result_arg (a: result<_, _>, b: result<_, [e1](#e1)>, c: result<[e1](#e1), _>, d: result, tuple<>>, e: result, f: result>)` +` func result_arg (a: result<_, _>, b: result<_, [e1](#e1)>, c: result<[e1](#e1), _>, d: result, tuple<>>, e: result, f: result>)` ### Function result_result -`func result_result () -> tuple, result<_, [e1](#e1)>, result<[e1](#e1), _>, result, tuple<>>, result, result>>` +` func result_result () -> tuple, result<_, [e1](#e1)>, result<[e1](#e1), _>, result, tuple<>>, result, result>>` ### Function return_result_sugar -`func return_result_sugar () -> result` +` func return_result_sugar () -> result` ### Function return_result_sugar2 -`func return_result_sugar2 () -> result<_, [my_errno](#my_errno)>` +` func return_result_sugar2 () -> result<_, [my_errno](#my_errno)>` ### Function return_result_sugar3 -`func return_result_sugar3 () -> result<[my_errno](#my_errno), [my_errno](#my_errno)>` +` func return_result_sugar3 () -> result<[my_errno](#my_errno), [my_errno](#my_errno)>` ### Function return_result_sugar4 -`func return_result_sugar4 () -> result, [my_errno](#my_errno)>` +` func return_result_sugar4 () -> result, [my_errno](#my_errno)>` ### Function return_option_sugar -`func return_option_sugar () -> option` +` func return_option_sugar () -> option` ### Function return_option_sugar2 -`func return_option_sugar2 () -> option<[my_errno](#my_errno)>` +` func return_option_sugar2 () -> option<[my_errno](#my_errno)>` ### Function result_simple -`func result_simple () -> result` +` func result_simple () -> result` ### Function is_clone_arg -`func is_clone_arg (a: [is_clone](#is_clone))` +` func is_clone_arg (a: [is_clone](#is_clone))` ### Function is_clone_return -`func is_clone_return () -> [is_clone](#is_clone)` +` func is_clone_return () -> [is_clone](#is_clone)` ### Function return_named_option -`func return_named_option () -> (a: option)` +` func return_named_option () -> (a: option)` ### Function return_named_result -`func return_named_result () -> (a: result)` +` func return_named_result () -> (a: result)` diff --git a/src/main.rs b/src/main.rs index 083b713e..7e3d58ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,7 +148,7 @@ fn run() -> Result<()> { Command::Markdown { builder, world } => { let (path, contents) = gen_interface(builder, world)?; - write_file(&out_dir, &path, &contents)?; + write_file(out_dir, &path, &contents)?; } };