@@ -46,17 +46,20 @@ pub struct State {
46
46
47
47
impl State {
48
48
pub fn restore_from_parent_dir ( parent_dir : & Path ) -> anyhow:: Result < Self > {
49
- log:: info!( "Loading saved settings from: {}" , parent_dir. display( ) ) ;
49
+ log:: info!(
50
+ "Loading saved settings from: {parent_dir}" ,
51
+ parent_dir = parent_dir. display( )
52
+ ) ;
50
53
let mut settings = Self :: load ( parent_dir)
51
54
. map_err ( |err| {
52
- log:: warn!( "Failed to load saved settings: {}" , err ) ;
55
+ log:: warn!( "Failed to load saved settings: {err}" ) ;
53
56
} )
54
57
. unwrap_or_default ( ) ;
55
58
if settings. database_url . is_none ( ) {
56
59
let database_file_path = default_database_file_path ( parent_dir. to_path_buf ( ) ) ;
57
60
log:: info!(
58
- "Using default SQLite database: {}" ,
59
- database_file_path. display( )
61
+ "Using default SQLite database: {database_file_path }" ,
62
+ database_file_path = database_file_path . display( )
60
63
) ;
61
64
settings. database_url = Url :: from_file_path ( & database_file_path) . ok ( ) ;
62
65
}
@@ -66,7 +69,10 @@ impl State {
66
69
67
70
pub fn load ( parent_dir : & Path ) -> anyhow:: Result < State > {
68
71
let file_path = new_settings_file_path ( parent_dir. to_path_buf ( ) ) ;
69
- log:: info!( "Loading settings from file: {}" , file_path. display( ) ) ;
72
+ log:: info!(
73
+ "Loading settings from file: {file_path}" ,
74
+ file_path = file_path. display( )
75
+ ) ;
70
76
match fs:: read ( & file_path) {
71
77
Ok ( bytes) => ron:: de:: from_bytes ( & bytes) . map_err ( Into :: into) ,
72
78
Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( Default :: default ( ) ) ,
@@ -76,7 +82,10 @@ impl State {
76
82
77
83
pub fn save ( & self , parent_dir : & Path ) -> anyhow:: Result < ( ) > {
78
84
let file_path = new_settings_file_path ( parent_dir. to_path_buf ( ) ) ;
79
- log:: info!( "Saving current settings into file: {}" , file_path. display( ) ) ;
85
+ log:: info!(
86
+ "Saving current settings into file: {file_path}" ,
87
+ file_path = file_path. display( )
88
+ ) ;
80
89
let mut bytes = vec ! [ ] ;
81
90
ron:: ser:: to_writer_pretty ( & mut bytes, self , Default :: default ( ) ) ?;
82
91
if let Some ( parent_path) = file_path. parent ( ) {
@@ -122,7 +131,7 @@ impl State {
122
131
. ok_or_else ( || anyhow:: anyhow!( "missing database URL" ) ) ?;
123
132
let file_path = url
124
133
. to_file_path ( )
125
- . map_err ( |( ) | anyhow:: anyhow!( "unsupported database URL: {}" , url ) ) ?;
134
+ . map_err ( |( ) | anyhow:: anyhow!( "unsupported database URL: {url}" ) ) ?;
126
135
let config = DatabaseConfig {
127
136
connection : aoide_storage_sqlite:: connection:: Config {
128
137
storage : aoide_storage_sqlite:: connection:: Storage :: File { path : file_path } ,
@@ -139,19 +148,20 @@ impl State {
139
148
Ok ( config)
140
149
}
141
150
142
- pub fn update_music_dir ( & mut self , new_music_dir : Option < & DirPath < ' _ > > ) -> bool {
143
- if self . music_dir . as_ref ( ) == new_music_dir {
144
- log:: debug!( "Unchanged music directory: {new_music_dir :?}" ) ;
151
+ pub fn update_music_dir ( & mut self , music_dir : Option < & DirPath < ' _ > > ) -> bool {
152
+ if self . music_dir . as_ref ( ) == music_dir {
153
+ log:: debug!( "Unchanged music directory: {music_dir :?}" ) ;
145
154
return false ;
146
155
}
147
- if let Some ( new_music_dir) = new_music_dir {
148
- log:: info!( "Updating music directory: {}" , new_music_dir. display( ) ) ;
156
+ if let Some ( music_dir) = music_dir {
157
+ log:: info!(
158
+ "Updating music directory: {music_dir}" ,
159
+ music_dir = music_dir. display( )
160
+ ) ;
149
161
} else {
150
162
log:: info!( "Resetting music directory" ) ;
151
163
}
152
- self . music_dir = new_music_dir
153
- . map ( ToOwned :: to_owned)
154
- . map ( DirPath :: into_owned) ;
164
+ self . music_dir = music_dir. map ( ToOwned :: to_owned) . map ( DirPath :: into_owned) ;
155
165
true
156
166
}
157
167
}
@@ -199,8 +209,8 @@ impl ObservableState {
199
209
}
200
210
201
211
#[ allow( clippy:: must_use_candidate) ]
202
- pub fn update_music_dir ( & self , new_music_dir : Option < & DirPath < ' _ > > ) -> bool {
203
- self . 0 . modify ( |state| state. update_music_dir ( new_music_dir ) )
212
+ pub fn update_music_dir ( & self , music_dir : Option < & DirPath < ' _ > > ) -> bool {
213
+ self . 0 . modify ( |state| state. update_music_dir ( music_dir ) )
204
214
}
205
215
}
206
216
0 commit comments