Skip to content

Commit 12b4159

Browse files
feat(core): add Specta integration (#9392)
1 parent ac9bfad commit 12b4159

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

Diff for: .changes/core-specta-integration.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:feat
3+
---
4+
5+
Add `specta` feature flag which adds `specta` support for `AppHandle`, `State`, `Window`, `Webview` and `WebviewWindow` types.

Diff for: Cargo.lock

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: core/tauri/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ features = [
2323
"devtools",
2424
"image-png",
2525
"protocol-asset",
26-
"test"
26+
"test",
27+
"specta"
2728
]
2829
rustc-args = [ "--cfg", "docsrs" ]
2930
rustdoc-args = [ "--cfg", "docsrs" ]
@@ -74,6 +75,7 @@ tracing = { version = "0.1", optional = true }
7475
heck = "0.4"
7576
log = "0.4"
7677
dunce = "1"
78+
specta = { version = "^2.0.0-rc.9", optional = true, default-features = false, features = ["function"] }
7779

7880
[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]
7981
muda = { version = "0.13", default-features = false, features = [ "serde" ] }
@@ -156,6 +158,7 @@ config-toml = [ "tauri-macros/config-toml" ]
156158
image-ico = [ "image/ico" ]
157159
image-png = [ "image/png" ]
158160
macos-proxy = [ "tauri-runtime-wry/macos-proxy" ]
161+
specta = ["dep:specta"]
159162

160163
[[example]]
161164
name = "commands"

Diff for: core/tauri/src/lib.rs

+36
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//! - **image-ico**: Adds support to parse `.ico` image, see [`Image`].
3838
//! - **image-png**: Adds support to parse `.png` image, see [`Image`].
3939
//! - **macos-proxy**: Adds support for [`WebviewBuilder::proxy_url`] on macOS. Requires macOS 14+.
40+
//! - **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)
4041
//!
4142
//! ## Cargo allowlist features
4243
//!
@@ -986,6 +987,41 @@ pub(crate) use run_main_thread;
986987
#[cfg_attr(docsrs, doc(cfg(feature = "test")))]
987988
pub mod test;
988989

990+
#[cfg(feature = "specta")]
991+
const _: () = {
992+
use specta::{function::FunctionArg, DataType, TypeMap};
993+
994+
impl<'r, T: Send + Sync + 'static> FunctionArg for crate::State<'r, T> {
995+
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
996+
None
997+
}
998+
}
999+
1000+
impl<R: crate::Runtime> FunctionArg for crate::AppHandle<R> {
1001+
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
1002+
None
1003+
}
1004+
}
1005+
1006+
impl<R: crate::Runtime> FunctionArg for crate::Window<R> {
1007+
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
1008+
None
1009+
}
1010+
}
1011+
1012+
impl<R: crate::Runtime> FunctionArg for crate::Webview<R> {
1013+
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
1014+
None
1015+
}
1016+
}
1017+
1018+
impl<R: crate::Runtime> FunctionArg for crate::WebviewWindow<R> {
1019+
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
1020+
None
1021+
}
1022+
}
1023+
};
1024+
9891025
#[cfg(test)]
9901026
mod tests {
9911027
use cargo_toml::Manifest;

0 commit comments

Comments
 (0)