How to check if a file or directory exists in Rust?
Hello colleagues! I'm new to Rust and trying to write a simple file utility. I need to check if a file or directory exists at a given path before performing any operations on it (e.g., reading or deleting). I found the `std::path::Path::exists()` method in the documentation, but I'm not sure if this is the correct approach, as some discussions mention race conditions and issues with symbolic links.
Here's what I'm currently doing:
```rust
use std::path::Path;
fn main() {
let path = Path::new("/tmp/my_file.txt");
if path.exists() {
println!("File exists!");
} else {
println!("File not found.");
}
}
```
This code works, but I've heard that between the `exists()` check and the actual file opening, something can happen