Skip to content

Commit c770ff7

Browse files
committed
docs(examples): Move watch off of deprecated calls
1 parent b03a0f5 commit c770ff7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

examples/watch/main.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(deprecated)]
21
use std::collections::HashMap;
32
use std::path::Path;
43
use std::sync::mpsc::channel;
@@ -12,15 +11,23 @@ use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher};
1211
fn settings() -> &'static RwLock<Config> {
1312
static CONFIG: OnceLock<RwLock<Config>> = OnceLock::new();
1413
CONFIG.get_or_init(|| {
15-
let mut settings = Config::default();
16-
settings
17-
.merge(File::with_name("examples/watch/Settings.toml"))
18-
.unwrap();
14+
let settings = load();
1915

2016
RwLock::new(settings)
2117
})
2218
}
2319

20+
fn refresh() {
21+
*settings().write().unwrap() = load();
22+
}
23+
24+
fn load() -> Config {
25+
Config::builder()
26+
.add_source(File::with_name("examples/watch/Settings.toml"))
27+
.build()
28+
.unwrap()
29+
}
30+
2431
fn show() {
2532
println!(
2633
" * Settings :: \n\x1b[31m{:?}\x1b[0m",
@@ -63,7 +70,7 @@ fn watch() -> ! {
6370
..
6471
})) => {
6572
println!(" * Settings.toml written; refreshing configuration ...");
66-
settings().write().unwrap().refresh().unwrap();
73+
refresh();
6774
show();
6875
}
6976

0 commit comments

Comments
 (0)