hocon.rs
hocon.rs copied to clipboard
std::time::Duration is an invalid type for "1 second"
Hi, I'm using hocon 0.4.0 and serde 1.0.124. The config file says blah = 1 second, the config struct says blah: std::time::Duration, and hocon says
Error: Error deserializing: "blah: invalid type for field \"blah\""
When I change the struct's field type from std::time::Duration to String, then the struct field successfully gets the textual value 1 second.
Am I doing something wrong please? I looked into Hocon's source code and it looks like std::time::Duration is supported.
PS. Hocon is the best config format ever, loved it since Scala times, thanks for your work.
Thanks you for reporting this!
Duration formats were supported in Hocon formats, but not all the way through deserialization... They now are (in 0.5.1), with an api inspired by humantime-serde
Either with an attribute: https://github.com/mockersf/hocon.rs/blob/0433e51e17f831aaa4ec7b39dadb5bc9c2b06f07/tests/deserialize.rs#L129-L133
Or with a wrapper type: https://github.com/mockersf/hocon.rs/blob/0433e51e17f831aaa4ec7b39dadb5bc9c2b06f07/tests/deserialize.rs#L113-L116
See the doc here: https://docs.rs/hocon/0.5.1/hocon/de/wrappers/struct.Serde.html