Browse Source

refactor(core): change `setup` closure type to `FnOnce`, closes #3061 (#3065)

Lucas Fernandes Nogueira 3 years ago
parent
commit
3f3599b9cc
3 changed files with 7 additions and 2 deletions
  1. 5 0
      .changes/setup-fn-once.md
  2. 1 1
      core/tauri/src/app.rs
  3. 1 1
      core/tauri/src/hooks.rs

+ 5 - 0
.changes/setup-fn-once.md

@@ -0,0 +1,5 @@
+---
+"tauri": "patch"
+---
+
+`Builder#setup` closure type changed from `Fn` to `FnOnce`.

+ 1 - 1
core/tauri/src/app.rs

@@ -677,7 +677,7 @@ impl<R: Runtime> Builder<R> {
   /// Defines the setup hook.
   pub fn setup<F>(mut self, setup: F) -> Self
   where
-    F: Fn(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send + 'static,
+    F: FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send + 'static,
   {
     self.setup = Box::new(setup);
     self

+ 1 - 1
core/tauri/src/hooks.rs

@@ -16,7 +16,7 @@ use tauri_macros::default_runtime;
 
 /// A closure that is run when the Tauri application is setting up.
 pub type SetupHook<R> =
-  Box<dyn Fn(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send>;
+  Box<dyn FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error + Send>> + Send>;
 
 /// A closure that is run everytime Tauri receives a message it doesn't explicitly handle.
 pub type InvokeHandler<R> = dyn Fn(Invoke<R>) + Send + Sync + 'static;