-
Notifications
You must be signed in to change notification settings - Fork 26
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
Convert MaxSpeed to consistent JSON format (a float of meters per second) #272
Comments
Why can we just do enum with two variants where one variant has two required fields (and the unit is an enum of course) and the other has none? enum SpeedLimit {
Unlimited,
Unknown,
Posted {
speed: f32,
unit: SpeedUnit
}
} And for platform code that wants it in a standard unit, we can have methods on the enum impl. We can't expose these in UniFFI directly but we can expose top level functions for convenience. This should keep the data model lossless while letting us centralize conversion logic where it's needed for some purpose other than display. |
We can absolutely just provide the custom deserializers on each platform required to handle the untouched On Swift we can provide a custom My main goal is avoiding friction when you define your slightly custom Attributes model on whatever platform. Enum with value patterns are not commonly very nice with serialization tools. Rust serde is the exception where it works perfectly out of the box. |
Yeah, understood. I think we can do that with the UniFFI magic in the toml file we were chatting about earlier. I'd be happy to put in some work next week to make that happen if you can work up some rough code that you'd like to see compilable. (i.e. draft of something that probably doesn't work but that you'd like to just magically work) I think we're getting close on this :D |
I also see you had implemented some of the ideas already in your PR now :P Still working through that... |
Think this can be dropped as a result of #287. Android may be a little harder, but the benefits of this system seem to be solid enough as demonstrated on the iOS ticket. |
The MaxSpeed json object has two formats:
{"unknown": true}
- The speed limit is unknown{"speed":30.2,"unit":"km/h"}
- The speed is unknown and potentially the localized unit (depending on API).This is an annoying object to deserialize on some platforms where json serialization requires typed references often requiring a custom decode handler. Because of this, it's probably best that we fix this once in rust to standardize the type definition. Suggestion is probably:
This is a much easier thing to deserialize as it always has the same type definition on a platform.
The text was updated successfully, but these errors were encountered: