Hey there everyone
I have a rust workspace so I don't duplicate compilation artifacts between a serial and a parallel version of a code. I.e. my workspace looks roughly like this
project
-- parallel
-- -- Cargo.toml
-- -- config.toml
-- -- main.rs
-- -- ...
-- serial
-- -- ...
-- Cargo.toml
-- target
-- -- ...
Now my question. I wanna be able to run the parallel code either from the workspace folder or from the parallel
folder. In order to read the config.toml
that holds some parameters for my code I need to check two possible paths, depending on what my working directory is. I do it with the following code:
pub fn read_config() -> Config {
let path = Path::new("parallel/config.toml");
let path = if path.exists() {
path
} else {
Path::new("config.toml")
};
let config = config::Config::builder()
.add_source(config::File::with_name(path.to_str().unwrap()))
.add_source(config::Environment::with_prefix("MASS"))
.build()
.unwrap();
let settings: Config = config.try_deserialize().unwrap();
settings
}
Can you give me feedback on this. Is there a more idiomatic way to see whether one of two paths exists?