Closed BigBIueWhale closed 10 months ago
Thank you for your insightful suggestion regarding the use of lazy_static! in Rust. I've taken your advice to heart and restructured the code to implement the "openRustDirectorySniffer" and "closeRustDirectorySniffer" design pattern. This approach has indeed provided a more elegant and manageable way to handle state within the library. Additionally, inspired by your input, I've added a 'stop scanning' functionality, enhancing the control and efficiency of directory scanning processes. Your guidance was invaluable, and the code is now more robust and maintainable thanks to the changes made.
That is exactly what I meant. This is a common design pattern in C programming when trying to simulate OOP: You return a pointer to an opaque struct (essentially a void*), and the library is also responsible for freeing that opaque struct. This is good for compatibility with C APIs and it's also good practice that if a dynamic library allocates memory, it should be deallocated by the library itself, to avoid issues with custom allocators or different C runtimes.
lazy_static! considered harmful. Better off to use a "openRustDirectorySniffer" "closeRustDirectorySniffer" design pattern, that returned a handle to the state, which is then managed by this library.