To find the path of a JSON file in Rust, you can use the std::path::PathBuf
and std::env::current_dir()
methods to obtain a PathBuf
object representing the current working directory, then append the file name to it:
main.rs172 chars7 lines
Assuming that the example.json
file is located in the same directory as the Rust source code, this code will create a PathBuf
object representing the absolute path to the example.json
file. You can then use file_path
in your JSON file reading or writing code.
gistlibby LogSnag