You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an *experimental* crate to aid in generating Rust IPC bindings for [Tauri](https://tauri.app/) commands (for those of us who'd like to use Rust for the front-end). Please review the code before using it.
5
+
IPC bindings for using [Tauri](https://v2.tauri.app/) with a Rust Frontend (e.g.
**NOTE:** The API is currently unstable and may change.
6
9
7
10
## Why
8
11
9
-
I couldn't find a comfortable way of defining commands that would maintain type safety with Tauri IPC bindings for a Rust frontend. So this is a crude attempt at solving this without changing too much about how the commands are defined.
12
+
I couldn't find a comfortable way of defining commands that would maintain type
13
+
safety with Tauri IPC bindings for a Rust Frontend. So this is a crude attempt
14
+
at solving this without changing too much about how the commands are defined.
10
15
11
16
## Usage
12
17
@@ -41,9 +46,12 @@ I couldn't find a comfortable way of defining commands that would maintain type
41
46
}
42
47
```
43
48
44
-
**NOTE:** If you have multiple enums deriving `Events`, these will need to be in separate modules since there's some common boilerplate types that are included currently (that will be moved into another crate at some point).
49
+
**NOTE:** If you have multiple enums deriving `Events`, these will need to
50
+
be in separate modules since there's some common boilerplate types that are
51
+
included currently (that will be moved into another crate at some point).
45
52
46
-
And if you're using a plugin on the frontend and want bindings generated for it, you can do so by defining a trait for it, e.g:
53
+
And if you're using a plugin on the frontend and want bindings generated for
54
+
it, you can do so by defining a trait for it, e.g:
47
55
48
56
```rust
49
57
pub mod someplugin {
@@ -55,7 +63,16 @@ I couldn't find a comfortable way of defining commands that would maintain type
55
63
}
56
64
```
57
65
58
-
**NOTE:** If you have multiple traits implementing `invoke_bindings` they'll each need to be in their own `mod` since an `invoke` WASM binding will be derived in scope of where the trait is defined (this will be moved into another crate at some point).
66
+
**NOTE:** You can find the `cmd_prefix` and plugin API by looking at the
**NOTE:** If you have multiple traits implementing `invoke_bindings` they'll
73
+
each need to be in their own `mod` since an `invoke` WASM binding will be
74
+
derived in scope of where the trait is defined (this will be moved into
75
+
another module at some point).
59
76
60
77
2. Import the commands trait into your Tauri backend and wrap your command definitions in the `impl_trait` macro, e.g:
61
78
@@ -69,7 +86,18 @@ I couldn't find a comfortable way of defining commands that would maintain type
69
86
});
70
87
```
71
88
72
-
This will define a shadow struct with an `impl Commands` block with all the functions passed into the macro minus any fn generics or arguments where the type starts with `tauri::`, and spits out the actual fns untouched. The Rust compiler will then emit helpful errors if the defined commands are different (after being processed) from those in the trait, yay!
89
+
This will define a new struct named `__ImplCommands` with an `impl Commands
90
+
for __ImplCommands` block with all the fns passed into the macro (minus any
91
+
fn generics or arguments where the type starts with `tauri::`), and spits
92
+
out the actual fns untouched. The Rust compiler will then emit helpful
93
+
errors if the defined commands are different (after being processed) from
94
+
those in the trait, yay!
95
+
96
+
**NOTE:** The crudeness here is due to `#[tauri::command]`s needing to be
97
+
top level fns and potentially having additional arguments in the siganture.
98
+
And while I can imagine a way of abstracting this out of the API (so this
99
+
could be a regular `impl` block), this was the easiest thing and works
100
+
without changing much about how the commands are defined.
73
101
74
102
3. Import the event enum into your Tauri backend if you wish to emit events from there, e.g.:
0 commit comments