Skip to content

Commit

Permalink
feat(core): add Specta integration (#9392)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Apr 23, 2024
1 parent ac9bfad commit 12b4159
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/core-specta-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:feat
---

Add `specta` feature flag which adds `specta` support for `AppHandle`, `State`, `Window`, `Webview` and `WebviewWindow` types.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ features = [
"devtools",
"image-png",
"protocol-asset",
"test"
"test",
"specta"
]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
Expand Down Expand Up @@ -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" ] }
Expand Down Expand Up @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 12b4159

Please sign in to comment.