Hello. I want to manipulate files that all are in a common directory, and share the same extension. In shell, I would do:
path="${BASE_DIRECTORY}/${city}.txt"
What is the idiomatic way to do it in Rust? The following snippet works, but it's just one of the many way to do it. Is there as standard way?
use std::path::Path;
const BASE_DIRECTORY: &str = "/some/folder";
fn read_data_from_city(city: &str) -> Vec<f64> {
let path = Path::new(BASE_DIRECTORY).join([city, ".txt"].concat());
// open path and read data
}
EDIT: I noticed that I can't create a const Path so I modified BASE_DIRECTORY to be &str.
Mostly because there are so many way to do the same thing, that I don't know which one to choose, and the tradeoff aren't clear. Hence my question, what is the idiomatic way to do it.
The std::path module documentation lists let path: PathBuf = ["some", "string", "fragments"].iter().collect(); as the best way to turn a number of &str path fragments known up front into a path.