diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b838553..f278753 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}} @@ -44,7 +44,7 @@ jobs: RUSTFLAGS: ${{matrix.rustflags}} ${{env.RUSTFLAGS}} msrv: - name: Rust 1.70.0 + name: Rust MSRV needs: pre_ci if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest @@ -54,8 +54,10 @@ jobs: - name: install native dependecies run: | sudo apt-get update - sudo apt-get install -y webkit2gtk-4.0 libgtk-3-dev - - uses: dtolnay/rust-toolchain@1.70.0 + 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: + toolchain: 1.70.0 # MSRV - uses: Swatinem/rust-cache@v2 - run: cargo check --workspace --tests @@ -69,7 +71,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 diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml new file mode 100644 index 0000000..f31c7ed --- /dev/null +++ b/.github/workflows/spelling.yml @@ -0,0 +1,21 @@ +name: Spelling + +permissions: + contents: read + +on: [pull_request] + +env: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + CLICOLOR: 1 + +jobs: + spelling: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v3 + - name: Spell Check Repo + uses: crate-ci/typos@master diff --git a/Cargo.toml b/Cargo.toml index 2281aa0..40f8a1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "tauri-bindgen" authors.workspace = true version.workspace = true edition.workspace = true -rust-version.workspace = true +rust-version.workspace = true # MSRV [workspace] members = ["crates/*"] @@ -35,6 +35,7 @@ proc-macro2 = "1.0.67" syn = "2.0.33" schemars = "0.8.12" serde_json = "1.0" +tauri = "2.0.0-alpha.14" [dependencies] clap.workspace = true diff --git a/README.md b/README.md index c2f8404..9371aaa 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Here are a few reasons why that is cool: - **Compile-time Checks** -When using strongly typed languages, such as Rust, TypeScript or ReScript the generated code will automatically ensure that you are calling the API correctly, as long as it passes the type checking youre golden. This is especially neat **when working in a team**, so your colleagues can't just change command signatures and pull the rug out from under you. +When using strongly typed languages, such as Rust, TypeScript or ReScript the generated code will automatically ensure that you are calling the API correctly, as long as it passes the type checking your golden. This is especially neat **when working in a team**, so your colleagues can't just change command signatures and pull the rug out from under you. - **Easily auditable** diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index 039f74e..dda46a6 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -7,14 +7,14 @@ use heck::ToKebabCase; use heck::{ToSnakeCase, ToUpperCamelCase}; -use proc_macro2::TokenStream; +use proc_macro2::{Literal, TokenStream}; use quote::format_ident; use quote::quote; use std::collections::HashSet; use std::path::PathBuf; 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))] @@ -252,7 +252,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)), @@ -266,7 +266,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)* @@ -304,6 +310,131 @@ impl Host { } } + 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| { + let ctx = get_cx(ctx.data()); + + Ok(ctx.#func_ident(#param_acc)) + }, + )?; + } + } + } + + 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); + + 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()); + + 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.define( + #mod_name, + #func_name, + move | + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + p: (::tauri_bindgen_host::ResourceId, #(#param_decl),*) + | { + let ctx = get_cx(ctx.data()); + let r = ctx.#get_r_ident(p.0)?; + Ok(r.#func_ident(#param_acc)) + }, + )?; + } + } + } + fn print_add_to_router<'a>( &self, mod_ident: &str, @@ -314,104 +445,10 @@ impl Host { let mod_name = mod_ident.to_snake_case(); - let functions = functions.map(|func| { - let func_name = func.id.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); - - 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! { () }, - }; - - 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 functions = functions.map(|func| self.print_router_fn_definition(&mod_name, func)); let methods = methods.map(|(resource_name, method)| { - let func_name = method.id.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); - - 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! { () }, - }; - - let mod_name = format!("{mod_name}::resource::{resource_name}"); - let get_r_ident = format_ident!("get_{}", resource_name.to_snake_case()); - - 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, - this_rid: ::tauri_bindgen_host::ResourceId, - #params - | -> ::tauri_bindgen_host::anyhow::Result<#result> { - let ctx = get_cx(ctx.data()); - let r = ctx.#get_r_ident(this_rid)?; - - Ok(r.#func_ident(#(#param_idents),*)) - }, - )?; - } + self.print_router_method_definition(&mod_name, resource_name, method) }); quote! { @@ -420,6 +457,7 @@ impl Host { 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, { 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 0000000..1a8a576 --- /dev/null +++ b/crates/gen-host/tests/async/chars.rs @@ -0,0 +1,50 @@ +#[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, + { + 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 0000000..4e1dac9 --- /dev/null +++ b/crates/gen-host/tests/async/conventions.rs @@ -0,0 +1,197 @@ +#[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, + { + 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 0000000..eca4c28 --- /dev/null +++ b/crates/gen-host/tests/async/empty.rs @@ -0,0 +1,19 @@ +#[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, + { + 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 0000000..fa504cf --- /dev/null +++ b/crates/gen-host/tests/async/flegs.rs @@ -0,0 +1,173 @@ +#[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, + { + 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 0000000..2fa4d70 --- /dev/null +++ b/crates/gen-host/tests/async/floats.rs @@ -0,0 +1,76 @@ +#[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, + { + 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 0000000..5d4ea36 --- /dev/null +++ b/crates/gen-host/tests/async/integers.rs @@ -0,0 +1,347 @@ +#[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, + { + 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 0000000..0f08c14 --- /dev/null +++ b/crates/gen-host/tests/async/lists.rs @@ -0,0 +1,551 @@ +#[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, + { + 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 0000000..9ebfd1f --- /dev/null +++ b/crates/gen-host/tests/async/many-arguments.rs @@ -0,0 +1,134 @@ +#[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, + { + 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 0000000..0d2f0fe --- /dev/null +++ b/crates/gen-host/tests/async/multi-return.rs @@ -0,0 +1,90 @@ +#[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, + { + 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 0000000..90281e6 --- /dev/null +++ b/crates/gen-host/tests/async/records.rs @@ -0,0 +1,225 @@ +#[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, + { + 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 0000000..f5751e5 --- /dev/null +++ b/crates/gen-host/tests/async/resources.rs @@ -0,0 +1,182 @@ +#[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 + 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; + } + 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, + { + 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) + }) + }, + )?; + 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/async/simple-functions.rs b/crates/gen-host/tests/async/simple-functions.rs new file mode 100644 index 0000000..fe5d466 --- /dev/null +++ b/crates/gen-host/tests/async/simple-functions.rs @@ -0,0 +1,110 @@ +#[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, + { + 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 0000000..90e680a --- /dev/null +++ b/crates/gen-host/tests/async/simple-lists.rs @@ -0,0 +1,82 @@ +#[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, + { + 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 0000000..0772e27 --- /dev/null +++ b/crates/gen-host/tests/async/small-anonymous.rs @@ -0,0 +1,40 @@ +#[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, + { + 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 0000000..c929e1c --- /dev/null +++ b/crates/gen-host/tests/async/strings.rs @@ -0,0 +1,65 @@ +#[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/async/unions.rs b/crates/gen-host/tests/async/unions.rs new file mode 100644 index 0000000..9e18c60 --- /dev/null +++ b/crates/gen-host/tests/async/unions.rs @@ -0,0 +1,237 @@ +#[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, + { + 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 0000000..1c153db --- /dev/null +++ b/crates/gen-host/tests/async/variants.rs @@ -0,0 +1,496 @@ +#[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, + { + 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 0000000..2f797e8 --- /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 580baf1..e047b72 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/chars.rs b/crates/gen-host/tests/sync/chars.rs similarity index 73% rename from crates/gen-host/tests/chars.rs rename to crates/gen-host/tests/sync/chars.rs index 5ba05e8..c190973 100644 --- a/crates/gen-host/tests/chars.rs +++ b/crates/gen-host/tests/sync/chars.rs @@ -14,30 +14,26 @@ pub mod chars { 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, { 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 66% rename from crates/gen-host/tests/conventions.rs rename to crates/gen-host/tests/sync/conventions.rs index 93df9f7..d21acd7 100644 --- a/crates/gen-host/tests/conventions.rs +++ b/crates/gen-host/tests/sync/conventions.rs @@ -28,150 +28,129 @@ pub mod conventions { 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, { 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<()> { + 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 94% rename from crates/gen-host/tests/empty.rs rename to crates/gen-host/tests/sync/empty.rs index f21f546..ce40c8c 100644 --- a/crates/gen-host/tests/empty.rs +++ b/crates/gen-host/tests/sync/empty.rs @@ -9,6 +9,7 @@ pub mod empty { 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, { let wrapped_get_cx = ::std::sync::Arc::new(get_cx); diff --git a/crates/gen-host/tests/flegs.rs b/crates/gen-host/tests/sync/flegs.rs similarity index 76% rename from crates/gen-host/tests/flegs.rs rename to crates/gen-host/tests/sync/flegs.rs index 3a1d37d..be9dd4f 100644 --- a/crates/gen-host/tests/flegs.rs +++ b/crates/gen-host/tests/sync/flegs.rs @@ -72,98 +72,78 @@ pub mod flegs { 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, { 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 65% rename from crates/gen-host/tests/floats.rs rename to crates/gen-host/tests/sync/floats.rs index b64c552..d654d4b 100644 --- a/crates/gen-host/tests/floats.rs +++ b/crates/gen-host/tests/sync/floats.rs @@ -14,55 +14,46 @@ pub mod floats { 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, { 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 57% rename from crates/gen-host/tests/integers.rs rename to crates/gen-host/tests/sync/integers.rs index 1e2104d..5514926 100644 --- a/crates/gen-host/tests/integers.rs +++ b/crates/gen-host/tests/sync/integers.rs @@ -44,289 +44,229 @@ pub mod integers { 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, { 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<()> { + 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 63% rename from crates/gen-host/tests/lists.rs rename to crates/gen-host/tests/sync/lists.rs index 6530779..50b23ed 100644 --- a/crates/gen-host/tests/lists.rs +++ b/crates/gen-host/tests/sync/lists.rs @@ -82,423 +82,368 @@ pub mod lists { 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, { 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<()> { + 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<()> { + 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> { + 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<()> { + 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> { + 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> { + 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> { + 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> { + 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> { + 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 { + 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 64% rename from crates/gen-host/tests/many-arguments.rs rename to crates/gen-host/tests/sync/many-arguments.rs index 13873ff..f5d4576 100644 --- a/crates/gen-host/tests/many-arguments.rs +++ b/crates/gen-host/tests/sync/many-arguments.rs @@ -54,68 +54,71 @@ pub mod many_arguments { 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, { 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<()> { + 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<()> { + 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 68% rename from crates/gen-host/tests/multi-return.rs rename to crates/gen-host/tests/sync/multi-return.rs index 1eceb2c..4f9916d 100644 --- a/crates/gen-host/tests/multi-return.rs +++ b/crates/gen-host/tests/sync/multi-return.rs @@ -15,65 +15,56 @@ pub mod multi_return { 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, { 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 71% rename from crates/gen-host/tests/records.rs rename to crates/gen-host/tests/sync/records.rs index 9de4a9a..716cea3 100644 --- a/crates/gen-host/tests/records.rs +++ b/crates/gen-host/tests/sync/records.rs @@ -60,145 +60,130 @@ All of the fields are bool*/ 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, { 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<()> { + 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<()> { + 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<()> { + 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 { + 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 64% rename from crates/gen-host/tests/resources.rs rename to crates/gen-host/tests/sync/resources.rs index 00d5c72..6022bb1 100644 --- a/crates/gen-host/tests/resources.rs +++ b/crates/gen-host/tests/sync/resources.rs @@ -36,128 +36,118 @@ pub mod resources { 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, { 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()) }, )?; 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-host/tests/simple-functions.rs b/crates/gen-host/tests/sync/simple-functions.rs similarity index 66% rename from crates/gen-host/tests/simple-functions.rs rename to crates/gen-host/tests/sync/simple-functions.rs index 39b5e20..7f735cd 100644 --- a/crates/gen-host/tests/simple-functions.rs +++ b/crates/gen-host/tests/sync/simple-functions.rs @@ -16,85 +16,74 @@ pub mod simple_functions { 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, { 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<()> { + 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)> { + 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 69% rename from crates/gen-host/tests/simple-lists.rs rename to crates/gen-host/tests/sync/simple-lists.rs index 85dd425..eda7e5a 100644 --- a/crates/gen-host/tests/simple-lists.rs +++ b/crates/gen-host/tests/sync/simple-lists.rs @@ -14,59 +14,54 @@ pub mod simple_lists { 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, { 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)> { + 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>> { + 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 83% rename from crates/gen-host/tests/small-anonymous.rs rename to crates/gen-host/tests/sync/small-anonymous.rs index a3e1953..d928b77 100644 --- a/crates/gen-host/tests/small-anonymous.rs +++ b/crates/gen-host/tests/sync/small-anonymous.rs @@ -17,17 +17,16 @@ pub mod small_anonymous { 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, { 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/strings.rs b/crates/gen-host/tests/sync/strings.rs similarity index 69% rename from crates/gen-host/tests/strings.rs rename to crates/gen-host/tests/sync/strings.rs index 2801adb..68d0b7b 100644 --- a/crates/gen-host/tests/strings.rs +++ b/crates/gen-host/tests/sync/strings.rs @@ -13,46 +13,41 @@ pub mod strings { 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( "strings", "a", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - x: String, - | -> ::tauri_bindgen_host::anyhow::Result<()> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: String| { let ctx = get_cx(ctx.data()); - Ok(ctx.a(x)) + Ok(ctx.a(p)) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "strings", "b", - 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.b()) }, )?; let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); router - .func_wrap( + .define( "strings", "c", move | ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - a: String, - b: String, - | -> ::tauri_bindgen_host::anyhow::Result { + p: (String, String)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.c(a, b)) + 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 74% rename from crates/gen-host/tests/unions.rs rename to crates/gen-host/tests/sync/unions.rs index efca91c..500305c 100644 --- a/crates/gen-host/tests/unions.rs +++ b/crates/gen-host/tests/sync/unions.rs @@ -70,138 +70,135 @@ and is treated that way in some languages*/ 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, { 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 66% rename from crates/gen-host/tests/variants.rs rename to crates/gen-host/tests/sync/variants.rs index 8781692..9c50d88 100644 --- a/crates/gen-host/tests/variants.rs +++ b/crates/gen-host/tests/sync/variants.rs @@ -150,137 +150,98 @@ pub mod variants { 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, { 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< - ( + p: ( Option, Option<()>, Option, @@ -288,200 +249,171 @@ pub mod variants { Option, Option, Option>, - ), - > { + )| + { + let ctx = get_cx(ctx.data()); + 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 + .define( + "variants", + "option_result", + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p: ()| { let ctx = get_cx(ctx.data()); Ok(ctx.option_result()) }, )?; 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), - > { + p: (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6)| + { let ctx = get_cx(ctx.data()); - Ok(ctx.casts(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_arg", 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<()> { - let ctx = get_cx(ctx.data()); - Ok(ctx.result_arg(a, b, c, d, e, f)) - }, - )?; - let get_cx = ::std::sync::Arc::clone(&wrapped_get_cx); - router - .func_wrap( - "variants", - "result_result", - move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, - | -> ::tauri_bindgen_host::anyhow::Result< - ( + 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/gen-markdown/tests/chars.md b/crates/gen-markdown/tests/chars.md index c335ad1..5c69398 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 a3597f5..c5ac04d 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 a23dddd..faf3970 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 0faea39..100c96d 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 5e38429..eea7a62 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 25a8573..0fd333b 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 07ba432..0c417cd 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 d790759..ab5d8a5 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 6db8d4b..326a40a 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 9e7459f..c484b24 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 0a25f43..64a0a11 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 d5e139b..90a9724 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 2afb7f8..d572cf9 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 15e492d..a18900c 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 e2ad318..e4c6e58 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 0caa87b..3a65078 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/crates/host/Cargo.toml b/crates/host/Cargo.toml index 59b2984..6a1dd31 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 99a79fd..f6b902d 100644 --- a/crates/ipc-router-wip/Cargo.toml +++ b/crates/ipc-router-wip/Cargo.toml @@ -12,5 +12,6 @@ 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"] } +futures-util = "0.3.28" diff --git a/crates/ipc-router-wip/src/lib.rs b/crates/ipc-router-wip/src/lib.rs index 014a0d9..f0486d3 100644 --- a/crates/ipc-router-wip/src/lib.rs +++ b/crates/ipc-router-wip/src/lib.rs @@ -1,33 +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}, - sync::{mpsc::Sender, Arc, Mutex}, + future::Future, + marker::PhantomData, + pin::Pin, + sync::Arc, }; -use tauri::{AppHandle, Manager, Runtime}; -use url::Url; +use tauri::http::{header::CONTENT_TYPE, Request, Response, StatusCode}; -#[derive(Default)] -pub struct Router { +type Definition = + Box, &[u8]) -> anyhow::Result + Send + Sync + 'static>; + +enum CallResult { + Value(Vec), + Future(Pin>> + Send + 'static>>), +} + +pub struct Caller { data: Arc, - string2idx: HashMap, usize>, - strings: Vec>, - map: HashMap>, } -pub type Definition = - Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; - -pub struct Caller<'a, T> { - data: &'a T, -} - -impl<'a, T> Caller<'a, T> { +impl Caller { #[must_use] pub fn data(&self) -> &T { - self.data + &self.data } } @@ -37,53 +38,101 @@ 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], - res_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 .get(&key) .ok_or(anyhow::anyhow!("method not found"))?; - let caller = Caller { data: &*self.data }; + let caller = Caller { + data: self.data.clone(), + }; - handler(caller, params, res_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]; @@ -91,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); @@ -107,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; @@ -119,129 +186,44 @@ 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> 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)?; - - 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 { #[must_use] fn ipc_router(self, router: Router) -> Self; } -impl BuilderExt for tauri::Builder { +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); + let router = Arc::new(router); - log::debug!("call result {:?}", res); + self.register_asynchronous_uri_scheme_protocol("ipc", move |_app, req, responder| { + let router = router.clone(); - let mut resp = 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 - } + 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()) + .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); - - Ok(resp) - }) + responder.respond(response); + }); + }) } } -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(); +#[inline] +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('/') @@ -249,13 +231,15 @@ fn uri_scheme_handler_inner( log::debug!("ipc request for {:?}::{}", module, method); - let (res_tx, res_rx) = std::sync::mpsc::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.recv()?) + Ok(resp.body(response)?) } diff --git a/crates/wit-parser/src/error.rs b/crates/wit-parser/src/error.rs index d71cb93..0592f2d 100644 --- a/crates/wit-parser/src/error.rs +++ b/crates/wit-parser/src/error.rs @@ -76,7 +76,7 @@ pub enum Error { #[label("cannot be defined twice")] location: Span, }, - /// Types can't recursively refer to themselves as that would make then possibly infinitly-sized. + /// Types can't recursively refer to themselves as that would make then possibly infinitely-sized. /// In Rust the compiler would force you to use heap indirection, however such a thing doesn't exist in out type system. /// /// This wouldn't be a problem with the current JSON format, but a custom binary one would have this limitation so for future proofing we deny recursive types. diff --git a/docs/WIT.md b/docs/WIT.md index 363492b..847fc41 100644 --- a/docs/WIT.md +++ b/docs/WIT.md @@ -111,7 +111,7 @@ func greet(name: string) -> string At the top-level of each `wit` document lives the `interface` definition, file must contain exactly one such definition. The name you give to an interface will dictate the name of the generated module and printed debug output. -An interface may contain function declarations and type defintions. The order of declaration doesn't matter so you are free to define types after you have used them for example. +An interface may contain function declarations and type definitions. The order of declaration doesn't matter so you are free to define types after you have used them for example. ```wit interface empty {} diff --git a/examples/greet/src-tauri/Cargo.toml b/examples/greet/src-tauri/Cargo.toml index eea277e..cbcc8b2 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", 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 f84933d..2e01004 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/examples/greet/src-tauri/tauri.conf.json b/examples/greet/src-tauri/tauri.conf.json index 15e818e..828dc27 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, diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 39a2b6e..0000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] -} diff --git a/renovate.json5 b/renovate.json5 new file mode 100644 index 0000000..0e62e36 --- /dev/null +++ b/renovate.json5 @@ -0,0 +1,103 @@ +{ + // schedule: [ + // 'before 5am on the first day of the month', + //], + semanticCommits: 'enabled', + configMigration: true, + dependencyDashboard: true, + regexManagers: [ + { + customType: 'regex', + fileMatch: [ + '^rust-toolchain\\.toml$', + 'Cargo.toml$', + 'clippy.toml$', + '\\.clippy.toml$', + '^\\.github/workflows/ci.yml$', + '^\\.github/workflows/rust-next.yml$', + ], + matchStrings: [ + 'MSRV.*?(?\\d+\\.\\d+(\\.\\d+)?)', + '(?\\d+\\.\\d+(\\.\\d+)?).*?MSRV', + ], + depNameTemplate: 'rust', + packageNameTemplate: 'rust-lang/rust', + datasourceTemplate: 'github-releases', + }, + ], + packageRules: [ + { + commitMessageTopic: 'MSRV', + matchManagers: [ + 'regex', + ], + matchPackageNames: [ + 'rust', + ], + minimumReleaseAge: '252 days', // 6 releases * 6 weeks per release * 7 days per week + internalChecksFilter: 'strict', + }, + // Goals: + // - Keep version reqs low, ignoring compatible normal/build dependencies + // - Take advantage of latest dev-dependencies + // - Rollup safe upgrades to reduce CI runner load + // - Help keep number of versions down by always using latest breaking change + // - Have lockfile and manifest in-sync + { + matchManagers: [ + 'cargo', + ], + matchDepTypes: [ + 'build-dependencies', + 'dependencies', + ], + matchCurrentVersion: '>=0.1.0', + matchUpdateTypes: [ + 'patch', + ], + enabled: false, + }, + { + matchManagers: [ + 'cargo', + ], + matchDepTypes: [ + 'build-dependencies', + 'dependencies', + ], + matchCurrentVersion: '>=1.0.0', + matchUpdateTypes: [ + 'minor', + ], + enabled: false, + }, + { + matchManagers: [ + 'cargo', + ], + matchDepTypes: [ + 'dev-dependencies', + ], + matchCurrentVersion: '>=0.1.0', + matchUpdateTypes: [ + 'patch', + ], + automerge: true, + groupName: 'compatible (dev)', + }, + { + matchManagers: [ + 'cargo', + ], + matchDepTypes: [ + 'dev-dependencies', + ], + matchCurrentVersion: '>=1.0.0', + matchUpdateTypes: [ + 'minor', + ], + automerge: true, + groupName: 'compatible (dev)', + }, + ], +} diff --git a/src/main.rs b/src/main.rs index 748a334..9d2810d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ struct Cli { #[derive(Debug, Parser)] enum Command { - /// Check a defintion file for errors. + /// Check a definition file for errors. Check { #[clap(flatten)] world: WorldOpt, diff --git a/typos.toml b/typos.toml new file mode 100644 index 0000000..fd191eb --- /dev/null +++ b/typos.toml @@ -0,0 +1,4 @@ +[default.extend-words] +# Abbreviations +inout = "inout" +ser = "ser" diff --git a/update-fixtures.sh b/update-fixtures.sh index 14928ed..80f7af5 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 -