mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
Handle notify errors
This commit is contained in:
parent
b15e0a279b
commit
4110ae21af
20
src/watch.rs
20
src/watch.rs
@ -1,6 +1,8 @@
|
||||
use anyhow::{bail, Context, Result};
|
||||
use notify_debouncer_mini::{
|
||||
new_debouncer, notify::RecursiveMode, DebounceEventResult, DebouncedEventKind,
|
||||
new_debouncer,
|
||||
notify::{self, RecursiveMode},
|
||||
DebounceEventResult, DebouncedEventKind,
|
||||
};
|
||||
use std::{
|
||||
io::{self, BufRead, Write},
|
||||
@ -26,6 +28,7 @@ enum InputEvent {
|
||||
enum WatchEvent {
|
||||
Input(InputEvent),
|
||||
FileChange { exercise_ind: usize },
|
||||
NotifyErr(notify::Error),
|
||||
TerminalResize,
|
||||
}
|
||||
|
||||
@ -36,11 +39,8 @@ struct DebouceEventHandler {
|
||||
|
||||
impl notify_debouncer_mini::DebounceEventHandler for DebouceEventHandler {
|
||||
fn handle_event(&mut self, event: DebounceEventResult) {
|
||||
let Ok(event) = event else {
|
||||
// TODO
|
||||
return;
|
||||
};
|
||||
|
||||
let event = match event {
|
||||
Ok(event) => {
|
||||
let Some(exercise_ind) = event
|
||||
.iter()
|
||||
.filter_map(|event| {
|
||||
@ -59,7 +59,12 @@ impl notify_debouncer_mini::DebounceEventHandler for DebouceEventHandler {
|
||||
return;
|
||||
};
|
||||
|
||||
self.tx.send(WatchEvent::FileChange { exercise_ind });
|
||||
WatchEvent::FileChange { exercise_ind }
|
||||
}
|
||||
Err(e) => WatchEvent::NotifyErr(e),
|
||||
};
|
||||
|
||||
let _ = self.tx.send(event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,6 +130,7 @@ pub fn watch(state_file: &StateFile, exercises: &'static [Exercise]) -> Result<(
|
||||
watch_state.run_exercise_with_ind(exercise_ind)?;
|
||||
watch_state.render()?;
|
||||
}
|
||||
WatchEvent::NotifyErr(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user