I just published my first open source project in rust. It's live on crates.io as well on http://wachit.dev. It's a nodemon like file watcher for instant restarts. Would love to hear your reviews about it. I know the code is absolute crap since I am a beginner haha.
Very nice, thanks for sharing!
Tiny suggestion from someone who's slowly coming up in the ranks as a Rustacean: run cargo clippy over your code before you push. Clippy is one of the best tools to ever exist. Currently, it gives me four warnings about your codebase, one of which it can fix automatically.
Keep up the great work!
The functions called set_default_* seem misnamed. They all get the default values, and don't set anything.
More importantly, the first two stanzas of your should_restart function are cursed:
// You don't need to check if the list is empty. The for loop will handle that.
if self.ignore_list.len() > 0 {
for wf in &self.ignore_list {
//Here you clone thing string, but str::ends_with only needs a slice.
let mut fs = wf.clone();
if wf.starts_with(".") {
// Here you allocate a second string but you could just get a slice without the leading '.'.
fs = wf[1..].to_string();
}
if path.ends_with(&fs) {
return false;
}
}
}
Both can be reduced to something like, which doesn't allocate at all.
for wf in &self.ignore_list {
let fs = wf.strip_prefix('.').unwrap_or(&wf);
if path.ends_with(&fs) {
return false;
}
}