Skip to content

Commit

Permalink
reuse builder with macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed May 8, 2024
1 parent 951d0aa commit 60fed8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions examples/app/src-tauri/src/main.rs
Expand Up @@ -63,8 +63,10 @@ pub struct EmptyEvent;
#[derive(Type)]
pub struct Custom(String);

fn main() {
let (invoke_handler, register_events) = {
// We recommend re-using the builder via a macro rather than function as the builder's
// generics can be tricky to deal with
macro_rules! specta_builder {
() => {{
let builder = ts::builder()
.commands(tauri_specta::collect_commands![
hello_world,
Expand All @@ -81,8 +83,12 @@ fn main() {
#[cfg(debug_assertions)]
let builder = builder.path("../src/bindings.ts");

builder.build().unwrap()
};
builder
}};
}

fn main() {
let (invoke_handler, register_events) = specta_builder!().build().unwrap();

tauri::Builder::default()
.invoke_handler(invoke_handler)
Expand Down
2 changes: 2 additions & 0 deletions examples/custom-plugin/plugin/src/lib.rs
Expand Up @@ -14,6 +14,8 @@ fn add_numbers(a: i32, b: i32) -> i32 {
#[derive(Clone, serde::Serialize, specta::Type, Event)]
struct RandomNumber(i32);

// We recommend re-using the builder via a macro rather than function as the builder's
// generics can be tricky to deal with
macro_rules! specta_builder {
() => {
ts::builder()
Expand Down

0 comments on commit 60fed8b

Please sign in to comment.