Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Good file watching that provides flexible primitives absolutely requires:

- ok, a single ext4 file inode changes, and its filename matches my hardcoded string

- oh, you don’t want to match against just changes to “package.json” but you want to match against a regex? voila, now you need a regex engine

- what about handling a directory rename? should that trigger matches on all files in the renamed directory?

- should the file watcher be triggered once per file, or just every 5ms? turns out this depends on your use case

- how do symlinks fit into this story?

- let’s say i want to handle once every 5ms- how do i actually wait for 5ms? do i yield the thread? do i allow other async contexts to execute while i’m waiting? how do those contexts know when to execute and when to yield back to me? now you have an async runtime with timers

- how does buffering work? are there limits on how many file change events can be buffered? do i dynamically allocate more memory as more file changes get buffered? now you need a vector/arraylist implementation

And this is before you look at what this looks like on different platforms, or if you want polling fallbacks.

Can you do it with less dependencies? Probably, if you start making hard tradeoffs and adding even more complexity about what features you activate - but that only adds lines of code, it doesn’t remove them.

What you describe is ideologically nice, but in practice it’s over-optimizing for a goal that most people don’t really care about.



Are you 100% sure all these cases are handled by cargo-watch?


Yup. Every user facing case mentioned has a corresponding flag. The non-user facing stuff, like being cross platform, is common sense.

https://crates.io/crates/cargo-watch/8.5.2


Regex one stands out as a negative example here. Why does it have to be built-in instead of exposing a str -> bool filter lambda?


How does one pass a lambda to a CLI tool? Outside of using a regex or equivalent pattern syntax, I'm struggling to understand what you are proposing here.


This is in a context of file watching library. Although I'm not sure cargo-watch supports or even needs to support regex.


Now you need a general purpose embedded language interpreter to express your filter lambda? I'm not sure you've really made anything simpler.


I don't see why you want an embedded interpreter for this. Can you explain?


If you give a lambda to cargo-watch instead of a regexp, it has to be evaluated. Hence interpreter.


Why would you evaluate it using an interpreter? Since you are using it in the context of a rust lambda you compile it. You just have a rust file that calls cargo-watch as a library. Crafting an interpreter seems like an incredibly bad idea.


But now you have to know at compile time what you're watching, which is not what cargo-watch or any of the similar commands like entr do.


Considering you have a rust file and the dependency why wouldn't you compile it? It's not like rustc is not available when you are using cargo-watch.


Anyway, doing all that just so you don't have to write a regexp has all the hallmarks of overkill. Keep it simple.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: