mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-03 16:53:30 +02:00
Optimize the notify event handler
This commit is contained in:
@@ -5,7 +5,7 @@ use super::WatchEvent;
|
||||
|
||||
pub struct DebounceEventHandler {
|
||||
pub tx: Sender<WatchEvent>,
|
||||
pub exercise_paths: &'static [&'static str],
|
||||
pub exercise_names: &'static [&'static [u8]],
|
||||
}
|
||||
|
||||
impl notify_debouncer_mini::DebounceEventHandler for DebounceEventHandler {
|
||||
@@ -15,15 +15,24 @@ impl notify_debouncer_mini::DebounceEventHandler for DebounceEventHandler {
|
||||
let Some(exercise_ind) = event
|
||||
.iter()
|
||||
.filter_map(|event| {
|
||||
if event.kind != DebouncedEventKind::Any
|
||||
|| !event.path.extension().is_some_and(|ext| ext == "rs")
|
||||
{
|
||||
if event.kind != DebouncedEventKind::Any {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.exercise_paths
|
||||
let file_name = event.path.file_name()?.to_str()?.as_bytes();
|
||||
|
||||
if file_name.len() < 4 {
|
||||
return None;
|
||||
}
|
||||
let (file_name_without_ext, ext) = file_name.split_at(file_name.len() - 3);
|
||||
|
||||
if ext != b".rs" {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.exercise_names
|
||||
.iter()
|
||||
.position(|path| event.path.ends_with(path))
|
||||
.position(|exercise_name| *exercise_name == file_name_without_ext)
|
||||
})
|
||||
.min()
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user