소스 검색

Add documentation on multiple commands (fix #1981) (#1982)

Gabe Cohen 4 년 전
부모
커밋
fb1f483a33
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 25 0
      docs/usage/guides/command.md

+ 25 - 0
docs/usage/guides/command.md

@@ -159,6 +159,31 @@ fn main() {
 }
 ```
 
+## Creating Multiple Commands
+
+The `tauri::generate_handler!` macro takes an array of commands. To register
+multiple commands, you cannot call invoke_handler multiple times. Only the last
+call will be used. You must pass each command to a single call of
+`tauri::generate_handler!`.
+
+```rust
+#[tauri::command]
+fn cmd_a() -> String {
+	"Command a"
+}
+#[tauri::command]
+fn cmd_b() -> String {
+	"Command b"
+}
+
+fn main() {
+  tauri::Builder::default()
+    .invoke_handler(tauri::generate_handler![cmd_a, cmd_b])
+    .run(tauri::generate_context!())
+    .expect("error while running tauri application");
+}
+```
+
 ## Complete Example
 
 Any or all of the above features can be combined: