Booleans can't have preceding whitespace
Friendly-Banana opened this issue · comments
According to the HJSON syntax
Preceding and trailing whitespace is ignored
let ping: bool = deser_hjson::from_str(r#"ping: true"#).unwrap();
fails with Syntax { line: 1, col: 1, code: ExpectedBoolean, at: "ping: true" }
. Run on Playground
let ping: bool = deser_hjson::from_str(r#"ping:true"#).unwrap();
works as expected
There's a bug, but your test case is weird: r#"ping: true"#
shouldn't deserialize into a bool
but into either a HashMap<String, bool>
or a struct like this:
#[derive(Deserialize)]
struct Bool {
ping: bool,
}
Thanks for the report!
BTW many people may have missed it (me included) because it doesn't happen when you use eg an Option<bool>
instead of a bool
, and an Option<bool>
is more often the best solution for configuration.
You're right, this is part of a struct, I just took this for a minimal example.
I use serde default, so the config is optional, I just like that way better.
Thanks for the quick fix!
I use serde default, so the config is optional, I just like that way better.
It totally depends on your use case, of course, but the downside of using serde default is that you don't know when the user explicitly sets a value. This matters when you have several configuration sources allowing overriding.