Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparently decode mixed lists of floats/integers into f64 #603

Open
tomtaylor opened this issue Mar 19, 2024 · 0 comments
Open

Transparently decode mixed lists of floats/integers into f64 #603

tomtaylor opened this issue Mar 19, 2024 · 0 comments
Milestone

Comments

@tomtaylor
Copy link

tomtaylor commented Mar 19, 2024

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 tomtaylor changed the title Transparently decode integer numbers into f64 Transparently decode mixed lists of floats/integers into f64 Mar 19, 2024
@filmor filmor added this to the 1.0 milestone Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants