I'm new to Rust, and I'm trying to create a small toy application that interacts with the File System.
I would like to write this is combination with unit tests, but here's a problem, how to test the File System.
In other languages, I would usually do it by mocking away the File System?
Generally introducing traits for something you otherwise wouldn't need traits for makes your life harder. I usually just see people actually access the file system in tests in a temporary directory instead of trying to mock it out.
Alternatively I see people testing the algorithms directly, and refactoring such that actual file system calls are outside that piece of code.
As far as the compiler is concerned, filesys might need to access dir’s memory later, but dir is destroyed when delete_wrapper exits. If it did, that would be a use-after-free bug.
I would recommend using a String as the type of deleted_directory. Otherwise you really do need the lifetime, and the variable with the path cannot be destroyed before the FileSystem object is destroyed as in @2e71828 example.