rustler icon indicating copy to clipboard operation
rustler copied to clipboard

Transparently decode mixed lists of floats/integers into `f64`

Open tomtaylor opened this issue 1 year ago • 0 comments

I'm trying to decode a list of Elixir numbers representing coordinates into f64, however, sometimes some of the coordinates are actually integers (ie. 0, not 0.0), because they're decoded from a JSON file which doesn't differentiate.

At the moment Rustler returns an error Could not decode field :coordinates on %MultiPolygon{}, but I'd like it to transparently convert the integer to a float, or offer some way of configuring that. Is there a way to make this work without losing all the convenience of NifStruct?

If useful, here's the code and failing test: https://github.com/breakroom/h3geo/tree/handle-integer-coordinates

tomtaylor avatar Mar 19 '24 08:03 tomtaylor