martinohmann / hcl-rs

HCL parsing and encoding libraries for rust with serde support
Apache License 2.0
121 stars 14 forks source link

Fraction-less floats are coerced into integers #310

Closed denfren closed 10 months ago

denfren commented 10 months ago

I noticed when using dts that floats are mangled when outputting hcl. I found this:

https://github.com/martinohmann/hcl-rs/blob/796707ab4ebfe6b83996aef4cce8d58ae2d51ced/crates/hcl-primitives/src/number.rs#L53-L58

Would it be an option not to do that and instead preserve the type?

denfren commented 10 months ago

Looking at the coercion logic I start to think that maybe it's better to accept that in the end everything is kind-of f64 and accept that .0 may not be written.

https://github.com/martinohmann/hcl-rs/blob/796707ab4ebfe6b83996aef4cce8d58ae2d51ced/crates/hcl-primitives/src/number.rs#L17-L22

JSON (and by extension probably YAML) also don't care about the underlying data type