5
5
use std:: {
6
6
collections:: HashMap ,
7
7
ffi:: OsStr ,
8
- fs:: { File , FileType } ,
9
- io:: { BufRead , Read , Write } ,
8
+ fs:: FileType ,
9
+ io:: { BufRead , Write } ,
10
10
path:: { Path , PathBuf } ,
11
11
process:: Command ,
12
12
str:: FromStr ,
13
13
sync:: { mpsc:: sync_channel, Arc , Mutex } ,
14
- time:: { Duration , Instant } ,
14
+ time:: Duration ,
15
15
} ;
16
16
17
17
use anyhow:: Context ;
@@ -126,22 +126,16 @@ impl Interface for Rust {
126
126
let manifest = {
127
127
let ( tx, rx) = sync_channel ( 1 ) ;
128
128
let mut watcher = new_debouncer ( Duration :: from_secs ( 1 ) , None , move |r| {
129
- if let Ok ( events ) = r {
130
- let _ = tx. send ( events ) ;
129
+ if let Ok ( _events ) = r {
130
+ let _ = tx. send ( ( ) ) ;
131
131
}
132
132
} )
133
133
. unwrap ( ) ;
134
- watcher. watch ( tauri_dir ( ) . join ( "Cargo.toml" ) , RecursiveMode :: Recursive ) ?;
135
- let ( manifest, _modified) = rewrite_manifest ( config) ?;
136
- let now = Instant :: now ( ) ;
137
- let timeout = Duration :: from_secs ( 2 ) ;
138
- loop {
139
- if now. elapsed ( ) >= timeout {
140
- break ;
141
- }
142
- if rx. try_recv ( ) . is_ok ( ) {
143
- break ;
144
- }
134
+ watcher. watch ( tauri_dir ( ) . join ( "Cargo.toml" ) , RecursiveMode :: NonRecursive ) ?;
135
+ let ( manifest, modified) = rewrite_manifest ( config) ?;
136
+ if modified {
137
+ // Wait for the modified event so we don't trigger a re-build later on
138
+ let _ = rx. recv_timeout ( Duration :: from_secs ( 2 ) ) ;
145
139
}
146
140
manifest
147
141
} ;
@@ -409,12 +403,10 @@ fn dev_options(
409
403
410
404
// Copied from https://github.com/rust-lang/cargo/blob/69255bb10de7f74511b5cef900a9d102247b6029/src/cargo/core/workspace.rs#L665
411
405
fn expand_member_path ( path : & Path ) -> crate :: Result < Vec < PathBuf > > {
412
- let Some ( path) = path. to_str ( ) else {
413
- return Err ( anyhow:: anyhow!( "path is not UTF-8 compatible" ) ) ;
414
- } ;
415
- let res = glob ( path) . with_context ( || format ! ( "could not parse pattern `{}`" , & path) ) ?;
406
+ let path = path. to_str ( ) . context ( "path is not UTF-8 compatible" ) ?;
407
+ let res = glob ( path) . with_context ( || format ! ( "could not parse pattern `{path}`" ) ) ?;
416
408
let res = res
417
- . map ( |p| p. with_context ( || format ! ( "unable to match path to pattern `{}`" , & path ) ) )
409
+ . map ( |p| p. with_context ( || format ! ( "unable to match path to pattern `{path }`" ) ) )
418
410
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
419
411
Ok ( res)
420
412
}
@@ -614,8 +606,7 @@ impl<T> MaybeWorkspace<T> {
614
606
) )
615
607
}
616
608
MaybeWorkspace :: Workspace ( TomlWorkspaceField { workspace : false } ) => Err ( anyhow:: anyhow!(
617
- "`workspace=false` is unsupported for `package.{}`" ,
618
- label,
609
+ "`workspace=false` is unsupported for `package.{label}`"
619
610
) ) ,
620
611
}
621
612
}
@@ -694,12 +685,9 @@ impl CargoSettings {
694
685
/// Try to load a set of CargoSettings from a "Cargo.toml" file in the specified directory.
695
686
fn load ( dir : & Path ) -> crate :: Result < Self > {
696
687
let toml_path = dir. join ( "Cargo.toml" ) ;
697
- let mut toml_str = String :: new ( ) ;
698
- let mut toml_file = File :: open ( toml_path) . with_context ( || "failed to open Cargo.toml" ) ?;
699
- toml_file
700
- . read_to_string ( & mut toml_str)
701
- . with_context ( || "failed to read Cargo.toml" ) ?;
702
- toml:: from_str ( & toml_str) . with_context ( || "failed to parse Cargo.toml" )
688
+ let toml_str = std:: fs:: read_to_string ( & toml_path)
689
+ . with_context ( || format ! ( "Failed to read {}" , toml_path. display( ) ) ) ?;
690
+ toml:: from_str ( & toml_str) . with_context ( || format ! ( "Failed to parse {}" , toml_path. display( ) ) )
703
691
}
704
692
}
705
693
@@ -976,10 +964,10 @@ impl AppSettings for RustAppSettings {
976
964
. unwrap ( )
977
965
. inner
978
966
. as_table ( )
979
- . get ( "package" )
980
- . and_then ( |p| p . as_table ( ) )
981
- . and_then ( |p| p . get ( "name" ) )
982
- . and_then ( |n| n . as_str ( ) )
967
+ . get ( "package" ) ?
968
+ . as_table ( ) ?
969
+ . get ( "name" ) ?
970
+ . as_str ( )
983
971
. map ( |n| n. to_string ( ) )
984
972
}
985
973
@@ -990,19 +978,18 @@ impl AppSettings for RustAppSettings {
990
978
. unwrap ( )
991
979
. inner
992
980
. as_table ( )
993
- . get ( "lib" )
994
- . and_then ( |p| p . as_table ( ) )
995
- . and_then ( |p| p . get ( "name" ) )
996
- . and_then ( |n| n . as_str ( ) )
981
+ . get ( "lib" ) ?
982
+ . as_table ( ) ?
983
+ . get ( "name" ) ?
984
+ . as_str ( )
997
985
. map ( |n| n. to_string ( ) )
998
986
}
999
987
}
1000
988
1001
989
impl RustAppSettings {
1002
990
pub fn new ( config : & Config , manifest : Manifest , target : Option < String > ) -> crate :: Result < Self > {
1003
991
let tauri_dir = tauri_dir ( ) ;
1004
- let cargo_settings =
1005
- CargoSettings :: load ( tauri_dir) . with_context ( || "failed to load cargo settings" ) ?;
992
+ let cargo_settings = CargoSettings :: load ( tauri_dir) . context ( "failed to load cargo settings" ) ?;
1006
993
let cargo_package_settings = match & cargo_settings. package {
1007
994
Some ( package_info) => package_info. clone ( ) ,
1008
995
None => {
@@ -1013,7 +1000,7 @@ impl RustAppSettings {
1013
1000
} ;
1014
1001
1015
1002
let ws_package_settings = CargoSettings :: load ( & get_workspace_dir ( ) ?)
1016
- . with_context ( || "failed to load cargo settings from workspace root" ) ?
1003
+ . context ( "failed to load cargo settings from workspace root" ) ?
1017
1004
. workspace
1018
1005
. and_then ( |v| v. package ) ;
1019
1006
@@ -1194,7 +1181,7 @@ fn get_cargo_option<'a>(args: &'a [String], option: &'a str) -> Option<&'a str>
1194
1181
pub fn get_workspace_dir ( ) -> crate :: Result < PathBuf > {
1195
1182
Ok (
1196
1183
get_cargo_metadata ( )
1197
- . with_context ( || "failed to get cargo metadata" ) ?
1184
+ . context ( "failed to get cargo metadata" ) ?
1198
1185
. workspace_root ,
1199
1186
)
1200
1187
}
0 commit comments