feat(core): add Specta integration (#9392)

This commit is contained in:
Oscar Beaumont 2024-04-23 10:29:39 +08:00 committed by GitHub
parent ac9bfada4a
commit 12b4159bda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch:feat
---
Add `specta` feature flag which adds `specta` support for `AppHandle`, `State`, `Window`, `Webview` and `WebviewWindow` types.

38
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<DataType> {
None
}
}
impl<R: crate::Runtime> FunctionArg for crate::AppHandle<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}
impl<R: crate::Runtime> FunctionArg for crate::Window<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}
impl<R: crate::Runtime> FunctionArg for crate::Webview<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}
impl<R: crate::Runtime> FunctionArg for crate::WebviewWindow<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}
};
#[cfg(test)]
mod tests {
use cargo_toml::Manifest;