remove uncessary arc
This commit is contained in:
parent
10731c22f4
commit
39a1037b33
1 changed files with 6 additions and 14 deletions
20
src/main.rs
20
src/main.rs
|
@ -171,22 +171,14 @@ fn start_watch(
|
||||||
config_data: ConfigData,
|
config_data: ConfigData,
|
||||||
) -> Result<Hotwatch, BunBunError> {
|
) -> Result<Hotwatch, BunBunError> {
|
||||||
let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?;
|
let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?;
|
||||||
|
let ConfigData { path, file } = config_data;
|
||||||
// Closures need their own copy of variables for proper life cycle management
|
let watch_result = watch.watch(&path, move |e: Event| {
|
||||||
let config_data = Arc::new(config_data);
|
|
||||||
let config_data_ref = Arc::clone(&config_data);
|
|
||||||
|
|
||||||
let watch_result = watch.watch(&config_data.path, move |e: Event| {
|
|
||||||
if let Event::Write(_) = e {
|
if let Event::Write(_) = e {
|
||||||
trace!("Grabbing writer lock on state...");
|
trace!("Grabbing writer lock on state...");
|
||||||
let mut state = state.write().expect("Failed to get write lock on state");
|
let mut state = state.write().expect("Failed to get write lock on state");
|
||||||
trace!("Obtained writer lock on state!");
|
trace!("Obtained writer lock on state!");
|
||||||
match read_config(
|
match read_config(file.try_clone().expect("Failed to clone file handle"))
|
||||||
config_data_ref
|
{
|
||||||
.file
|
|
||||||
.try_clone()
|
|
||||||
.expect("Failed to clone file handle"),
|
|
||||||
) {
|
|
||||||
Ok(conf) => {
|
Ok(conf) => {
|
||||||
state.public_address = conf.public_address;
|
state.public_address = conf.public_address;
|
||||||
state.default_route = conf.default_route;
|
state.default_route = conf.default_route;
|
||||||
|
@ -202,10 +194,10 @@ fn start_watch(
|
||||||
});
|
});
|
||||||
|
|
||||||
match watch_result {
|
match watch_result {
|
||||||
Ok(_) => info!("Watcher is now watching {:?}", &config_data.path),
|
Ok(_) => info!("Watcher is now watching {:?}", &path),
|
||||||
Err(e) => warn!(
|
Err(e) => warn!(
|
||||||
"Couldn't watch {:?}: {}. Changes to this file won't be seen!",
|
"Couldn't watch {:?}: {}. Changes to this file won't be seen!",
|
||||||
&config_data.path, e
|
&path, e
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue