Closed takluyver closed 6 years ago
Seems like an iterator would be in order here. It can be emulated slightly more elegantly than you did it with:
let basedirs = xdg::BaseDirectories::new().unwrap();
let config_dirs = [basedirs.get_config_home()].iter();
let config_dirs = config_dirs.chain(basedirs.get_config_dirs().rev());
for dir in config_dirs {
...
}
Thanks, that is more elegant. Shall I make a pull request? Do you want it just for config, or for data as well? I think it makes most sense for config, but it might be worth having both for symmetry.
Let's go with both, I can see uses for either. A PR sounds good. Do you know how to make new iterators?
I haven't made an iterator before, but do you mean like it's explained here, or is there a better way?
Oh I forgot how cool the Rust community is. This saves me the hassle of explaining it!
Great, I'll give it a go :-)
Apologies if I'm missing an easy way to do this with the existing methods, but I'd like a method to find instances of a config file from all the directories on the search path, so that user config can be merged with system config.
find_config_file()
only finds the first such file on the search path - I want them alllist_config_files()
lists files in a given subdirectory - I want to specify the filenameThis is what I've written in my application to do this (it's clumsy code, because I'm new to rust, but it might make it clearer what I mean):