iron / iron/params

Number overflow behavior

Open
#17 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
34
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Currently, `params::FromValue` uses `num::NumCast` to convert between JSON numbers and Rust numeric primitives. The behavior of `num::NumCast` is to return `None` on encountering a number too large for the destination type to contain. In these cases, depending on how `params` is used, deserialization will fail. Similarly, converting from `String` to a number primitive through `std::str::FromStr` has the same shortcoming.

Instead, should numbers that are too large simply be bounded to their destination type's extrema?

(Ruby on Rails, for example, is very lazy with this sort of conversion, deserializing huge numbers into the `Bignum` type. This leaves the overflow handling to the storage technology. This sort of approach is likely unfitting for a statically typed language.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.