config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Introduce an option for disabling the automatic resolver in FileSourceFile

Open eisterman opened this issue 5 years ago • 0 comments

If someone needs to import a specific file, excluding the resolve process, with the actual structure is impossible.

Example: The config file in the folder is called "config.toml" but the user asks for the file "config.ayeye". If I'm building the File with new or with_name, especially with new where you tell the FileFormat, the resolver in /src/file/source/file.rs line 37 if the file not exist search anyway other files with the same basename but one of the valid acceptable extension, reading the configuration from "config.toml" even if there was an error in the name.

That characteristic I'm sure is intended as a feature but in some peculiar case it can produce some very boring error, and only because the resolver cannot be disabled.

I'm proposing three solutions:

  1. Introduce a new FileSource named FileSourceExactFile and a new method in File named with_exact_name(&str, FileFormat) where the resolver is disabled. (I don't really like it as a solution)
  2. Add a flag to the FileSourceFile struct named use_resolver and modify the signature of new and/or with_name. (Breaking change is a big negative point)
  3. Add a flag to the FileSourceFile struct named use_resolver and add a method in File<FileSourceFile> similar to required(bool) where the user can enable or disable the resolver in FileSourceFile (The best solution. No breaking change, no removing of feature, only adding an option flag that if not used will be set to True for retro compatibility)

I'm building the solution 3 for my project, if it is accepted as a good idea, when ready I will send a Pull Request.

Opinion? Question? Observation?

eisterman avatar Mar 14 '20 02:03 eisterman