diff --git a/.changes/core-specta-integration.md b/.changes/core-specta-integration.md new file mode 100644 index 00000000000..f72c6abbc4f --- /dev/null +++ b/.changes/core-specta-integration.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:feat +--- + +Add `specta` feature flag which adds `specta` support for `AppHandle`, `State`, `Window`, `Webview` and `WebviewWindow` types. \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f5726294133..08a61182314 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "acl-tests" version = "0.1.0" @@ -2225,6 +2231,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3321,6 +3333,31 @@ dependencies = [ "system-deps", ] +[[package]] +name = "specta" +version = "2.0.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af8580b695a79b639706ecbc6b8f15a4570f38c4b208ea9fafa8362aace66d17" +dependencies = [ + "once_cell", + "paste", + "serde", + "specta-macros", + "thiserror", +] + +[[package]] +name = "specta-macros" +version = "2.0.0-rc.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68025f0a8950e26fae19b7ac334bd523179f4ef4e8c60e6875583a5bece6358e" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "spin" version = "0.9.8" @@ -3524,6 +3561,7 @@ dependencies = [ "serde_json", "serde_repr", "serialize-to-javascript", + "specta", "state", "swift-rs", "tauri", diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 7b39fbfa497..c08a949e8e7 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -23,7 +23,8 @@ features = [ "devtools", "image-png", "protocol-asset", - "test" + "test", + "specta" ] rustc-args = [ "--cfg", "docsrs" ] rustdoc-args = [ "--cfg", "docsrs" ] @@ -74,6 +75,7 @@ tracing = { version = "0.1", optional = true } heck = "0.4" log = "0.4" dunce = "1" +specta = { version = "^2.0.0-rc.9", optional = true, default-features = false, features = ["function"] } [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies] muda = { version = "0.13", default-features = false, features = [ "serde" ] } @@ -156,6 +158,7 @@ config-toml = [ "tauri-macros/config-toml" ] image-ico = [ "image/ico" ] image-png = [ "image/png" ] macos-proxy = [ "tauri-runtime-wry/macos-proxy" ] +specta = ["dep:specta"] [[example]] name = "commands" diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index bdf398b5aa3..a5e710200c4 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -37,6 +37,7 @@ //! - **image-ico**: Adds support to parse `.ico` image, see [`Image`]. //! - **image-png**: Adds support to parse `.png` image, see [`Image`]. //! - **macos-proxy**: Adds support for [`WebviewBuilder::proxy_url`] on macOS. Requires macOS 14+. +//! - **specta**: Add support for [`specta::specta`](https://docs.rs/specta/%5E2.0.0-rc.9/specta/attr.specta.html) with Tauri arguments such as [`State`](crate::State), [`Window`](crate::Window) and [`AppHandle`](crate::AppHandle) //! //! ## Cargo allowlist features //! @@ -986,6 +987,41 @@ pub(crate) use run_main_thread; #[cfg_attr(docsrs, doc(cfg(feature = "test")))] pub mod test; +#[cfg(feature = "specta")] +const _: () = { + use specta::{function::FunctionArg, DataType, TypeMap}; + + impl<'r, T: Send + Sync + 'static> FunctionArg for crate::State<'r, T> { + fn to_datatype(_: &mut TypeMap) -> Option { + None + } + } + + impl FunctionArg for crate::AppHandle { + fn to_datatype(_: &mut TypeMap) -> Option { + None + } + } + + impl FunctionArg for crate::Window { + fn to_datatype(_: &mut TypeMap) -> Option { + None + } + } + + impl FunctionArg for crate::Webview { + fn to_datatype(_: &mut TypeMap) -> Option { + None + } + } + + impl FunctionArg for crate::WebviewWindow { + fn to_datatype(_: &mut TypeMap) -> Option { + None + } + } +}; + #[cfg(test)] mod tests { use cargo_toml::Manifest;