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

ENH: Add as_res_f64 etc, analogous to as_opt_f64 but containing full error information in Err variant #6

Open
corneliusroemer opened this issue Mar 18, 2023 · 0 comments

Comments

@corneliusroemer
Copy link
Contributor

Description

Both the as_f64 and as_opt_f64 (see #5) functions throw away information:

  • as_f64 either coerces silently or errors the entire deserialization operation.
  • as_opt_f64 errors less, but contains no information on what went wrong when something goes wrong, as None has no inner value

It would make sense to add another function type as_res_f64, that keeps the error information around, so the downstream user can report and handle edge cases as desired.

The deserialization would then return `Res<f64, serde_this_or_that::Err>. The Error variant could contain:

  • The original value passed to as_res_f64, e.g. String("null") or bool::True etc.
  • Information on what failed, e.g. "bool cannot be coerced to f64"

There could also be different error kinds, so that users could handle them differently.

Before starting the implementation, it would probably be a good idea to work out the full behaviour matrix for various inputs

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

1 participant