Skip to content

Commit

Permalink
Non recursive collect_commands + upgrade Specta - closes #114
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 2, 2024
1 parent 70a84ef commit 98c8286
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 55 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ panic_in_result_fn = { level = "warn", priority = -1 }

[workspace.dependencies]
tauri = { version = "=2.0.0-beta.25" }
specta = { version = "=2.0.0-rc.18" }
specta-typescript = { version = "0.0.5" }
specta-jsdoc = { version = "0.0.5" }
specta = { version = "=2.0.0-rc.19" }
specta-typescript = { version = "0.0.6" }
specta-jsdoc = { version = "0.0.6" }

# [patch.crates-io]
# tauri = { git = "https://github.com/oscartbeaumont/tauri.git", rev = "ddc64b706a7f2db271d40e9b216187b1aa153efa" }
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//!
//! ```sh
//! # Always required
//! cargo add tauri@=2.0.0-beta.25 specta@=2.0.0-rc.18
//! cargo add tauri@=2.0.0-beta.25 specta@=2.0.0-rc.19
//!
//! # Typescript
//! cargo add [email protected].5
//! cargo add [email protected].6
//! cargo add tauri-specta@=2.0.0-rc.12 --features derive,typescript
//!
//! # JSDoc
//! cargo add [email protected].5
//! cargo add [email protected].6
//! cargo add tauri-specta@=2.0.0-rc.12 --features derive,javascript
//! ```
//!
Expand Down
45 changes: 4 additions & 41 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,13 @@
///
#[macro_export]
macro_rules! collect_commands {
// Hide distracting implementation details from the generated rustdoc.
($($t:tt)*) => {
$crate::collect_commands_internal!([] [] $($t)*)
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! collect_commands_internal {
() => {
($($b:tt $(:: $($p:ident)? $(<$g:path>)? )* ),*) => {
// We strip generics (::<...>) from being parsed to Tauri as it doesn't support them.
$crate::internal::command(
::tauri::generate_handler![],
::specta::function::collect_functions![],
::tauri::generate_handler![$($b $($(::$p)? )* ),*],
::specta::function::collect_functions![$($b $($(::$p)? $(::<$g>)? )* ),*],
)
};
// Alternate parsing mode between `<` and `>` where all chars are not put into `stripped` accumulator
([$($stripped:tt)*] [$($raw:tt)*] []) => {
compile_error!("Unexpected end of input. Did you forget to close a generic argument?");
};
([$($stripped:tt)*] [$($raw:tt)*] [] > $($rest:tt)*) => {
// Switch back to regular parsing mode
$crate::collect_commands_internal!([$($stripped)*] [$($raw)* >] $($rest)*)
};
([$($stripped:tt)*] [$($raw:tt)*] [] $a:tt $($rest:tt)*) => {
$crate::collect_commands_internal!([$($stripped)*] [$($raw)* $a] [] $($rest)*)
};
// Regular parsing mode
([$($stripped:tt)*] [$($raw:tt)*]) => {
$crate::internal::command(
::tauri::generate_handler![$($stripped)*],
::specta::function::collect_functions![$($raw)*],
)
};
([$($stripped:tt)*] [$($raw:tt)*] ::< $($rest:tt)*) => {
// Switch to alternate parsing mode
$crate::collect_commands_internal!([$($stripped)*] [$($raw)* ::<] [] $($rest)*)
};
([$($stripped:tt)*] [$($raw:tt)*] $a:tt $($rest:tt)*) => {
$crate::collect_commands_internal!([$($stripped)* $a] [$($raw)* $a] $($rest)*)
};
// Input
($($rest:tt)*) => {
$crate::collect_commands_internal!([] [] $($rest)*);
};
}

/// Collect events and their types.
Expand Down

0 comments on commit 98c8286

Please sign in to comment.