config-rs
config-rs copied to clipboard
Fix log::Level deserialization case sensitivity
This is an attempt to tackle #136
I believe to make this complete case-insensitive you would need to fix the check here: https://github.com/mehcode/config-rs/blob/bf09a730d44cb72f483dab04163dd75f2b9d1746/src/de.rs#L249
As this is checked for before even the actual log crate gets to deserialize, thus making it case-sensitive even if the log crate might not be.
Okay, so I have a patch, but it does not work. It is here
It is way harder to implement this, because the relevant code is deeply tied into serde and we cannot simply add settings to it. The problematic line is https://github.com/matthiasbeyer/config-rs/commit/33b8cf0eefffbe5ad656de1b691a668c942357f5#diff-be1c878c753064b7eaddf4a10ba4215a93dd1817d31e6788691cdb29752fd612R545 . I could, in theory, remove the From implementation and add some more powerful abstraction here, but the actual problem is not only this line, but also the Deserialize impl for Value, where we need to implement deserialization without having a Value object (or any other), so we cannot have settings at all.
I must say, I'm not sure whether this is possible at all, without rewriting large parts of this crate.
My question is why not let the enum try an deserialize itself? Why is the crate checking for a specific variant at all? You could try constructing a StrDeserializer directly.
TBH I don't know yet why this is done. I hope I get the chance to investigate this.
So the original title of this PR does not apply anymore. The patches here only test whether log levels can be deserialized.
I'll change the title accordingly. Still nice to get these patches in, after 1.5 years :laughing: